<?php

namespace App\Models;

use App\Entities\Agency;
use CodeIgniter\Model;

class AgencyModel extends Model
{
    protected $table          = 'agencies';
    protected $primaryKey     = 'id';
    protected $returnType     = Agency::class;
    protected $useSoftDeletes = true;
    protected $useTimestamps  = true;
    protected $allowedFields  = [
        'company_name', 'slug', 'logo_path', 'cover_image_path', 'website', 'email', 'phone',
        'industry', 'company_size', 'description', 'services', 'social_links', 'registration_number',
        'tax_number', 'address', 'verification_status', 'status',
        'owner_user_id', 'timezone',
    ];

    protected $validationRules = [
        'company_name' => 'required|min_length[2]|max_length[150]',
        'slug'         => 'required|alpha_dash|is_unique[agencies.slug,id,{id}]',
        'email'        => 'required|valid_email',
    ];

    public function findBySlug(string $slug): ?Agency
    {
        return $this->where('slug', $slug)->first();
    }
}
