<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;

class Project extends Model
{
    protected $fillable = ['project_number','client_id','pic_id','title','description','status','rab_amount','final_amount','start_date','end_date'];
    protected $casts    = ['start_date'=>'date','end_date'=>'date','rab_amount'=>'decimal:2','final_amount'=>'decimal:2'];

    public function client() { return $this->belongsTo(Client::class); }
    public function pic()    { return $this->belongsTo(User::class, 'pic_id'); }

    public static function generateNumber(): string
    {
        $year = date('Y');
        $seq  = str_pad(self::whereYear('created_at', $year)->count() + 1, 4, '0', STR_PAD_LEFT);
        return "PRJ-{$year}-{$seq}";
    }
}
