<?php

namespace App\Models;

use CodeIgniter\Model;

class SalaModel extends Model
{
    protected $table            = 'sala';
    protected $primaryKey       = 'id_sala';
    protected $useAutoIncrement = true;
    protected $returnType       = 'App\Entities\Sala';
    protected $useSoftDeletes   = false;
    protected $protectFields    = true;
    protected $allowedFields    = [
        'id_local',
        'nombre',
        'tipo',
        'capacidad',
        'estado'
    ];

    protected $validationRules = [
        'id_local'  => 'required|integer',
        'nombre'    => 'required|min_length[2]|max_length[80]',
        'tipo'      => 'required|in_list[2D,3D,IMAX,4DX]',
        'capacidad' => 'required|integer|greater_than[0]',
        'estado'    => 'permit_empty|in_list[0,1]',
    ];

    public function getSalasConLocal()
    {
        return $this->select('sala.*, local.nombre as local_nombre')
                    ->join('local', 'local.id_local = sala.id_local')
                    ->findAll();
    }
}
