<?php

namespace Modules\Redd\Models;

use CodeIgniter\Model;
use CodeIgniter\I18n\Time;

class ProjectGasesModel extends Model
{

  protected $table = 'redd_project_gases';
    protected $primaryKey = 'id';

    protected $allowedFields = ['project_id', 'gas_id'];

    protected $returnType     = 'array';
    protected $useTimestamps  = true;
    protected $useSoftDeletes = true;
    
    protected $createdField  = 'created_at';
    protected $updatedField  = 'updated_at';
    protected $deletedField  = 'deleted_at';


    public function getAll()
    {
        $builder = $this->db->table('redd_project_gases');
        $builder->where('deleted_at', null);
        $result = $builder->get()->getResult();
        return $result;
    }

    public function getProjectGases($project)
    {
        $builder = $this->db->table('redd_project_gases');
        $builder->select('redd_project_gases.*,')
                ->join('redd_projects', 'redd_projects.id=redd_project_gases.project_id')
                ->join('redd_gases', 'redd_gases.id=redd_project_gases.gas_id', 'left')
                ->where('redd_project_gases.deleted_at', null)
                ->where('redd_project_gases.project_id', $project);
        return $results = $builder->get()->getResult();
    }

    public function getByProject($projectId)
    {
        $builder = $this->db->table('redd_project_gases');
        $builder->select('redd_project_gases.*, name,symbol')
                ->join('redd_gases', 'redd_gases.id=redd_project_gases.gas_id', 'left')
                ->where('redd_project_gases.deleted_at', null)
                ->where('project_id', $projectId);
        return $results = $builder->get()->getResult();
    }

}