<?php namespace App\Models\Front;

class CustomerModel{
	protected $db;
	protected $session;
	protected $project;
	
    public function __construct(){
        $this->db = \Config\Database::connect();
		$this->session = session();
		$this->project = config('Config\\Project');
		$this->table = "customer";
    }
	

	public function insert_user($data){
		$builder = $this->db->table($this->table);
		$builder->insert($data);
		return $this->db->insertID();
	}
	public function insert_shortlist($data){
		$builder = $this->db->table('shortlisted');
		$builder->insert($data);
		return $this->db->insertID();
	}

	public function update($data, $id){
		$builder = $this->db->table('customer');
		$builder->where('customer_id',$id);
		$builder->update($data);
	}

	public function get_customer_detail($id){
		$builder = $this->db->table('customer AS cs');
		$query = $builder->select('cs.*')
		->where('cs.customer_id',$id)
		->where('cs.is_deleted','No')
		->where('cs.status','Active')
		->get();
		return $query->getRowArray();
	}
	public function get_artist_detail($id){
		$builder = $this->db->table('artist_registration AS ar');
		$query = $builder->select('ar.*,GROUP_CONCAT(DISTINCT g.name) AS genre_list,GROUP_CONCAT(DISTINCT c.name) AS creative_designation,c.url AS c_url,g.url AS g_url')
				->where('ar.artist_registration_id',$id)
				->join('artist_categories AS ac',"ar.artist_registration_id=ac.artist_registration_id",'inner')
				->join('artist_genre AS ag',"ar.artist_registration_id=ag.artist_registration_id",'inner')
				->join('genre AS g',"ag.genre_id=g.genre_id",'inner')
				->join('categories AS c',"ac.categories_id = c.categories_id",'inner')
				->where('ar.is_deleted','No')
				->where('ar.status','Active')
				->get();
		return $query->getRowArray();
	}

	public function get_my_artist_list($id){
		$builder = $this->db->table('shortlisted AS ms');
		$builder->select('ar.*,ms.shortlisted_id,GROUP_CONCAT(DISTINCT g.name) AS genre_list,GROUP_CONCAT(DISTINCT c.name) AS creative_designation,c.url AS c_url,g.url AS g_url')
				->join('customer AS cr',"ms.customer_id=cr.customer_id",'inner')
				->join('artist_registration AS ar',"ms.artist_registration_id=ar.artist_registration_id",'inner')
				->join('artist_categories AS ac',"ar.artist_registration_id=ac.artist_registration_id",'inner')
				->join('artist_genre AS ag',"ar.artist_registration_id=ag.artist_registration_id",'inner')
				->join('genre AS g',"ag.genre_id=g.genre_id",'inner')
				->join('categories AS c',"ac.categories_id = c.categories_id",'inner')
				->where('ms.customer_id',$id)
				->where('ms.is_deleted','No')
				->where('ms.status','Active');
	
		$builder->groupBy('ar.artist_registration_id');
		$query  = $builder->get();
		return $query->getResultArray();
	}
	
	public function delete_shortlist_artist($id){
		$data['is_deleted'] = "Yes";
		$data['status'] = "Inactive";
		$data['is_shortlist'] = "No";
		$builder = $this->db->table('shortlisted');
		$builder->where('shortlisted_id',$id)
				->update($data);
	}
}	