<?php

namespace App\Repositories;

use App\Models\CampaignBrief;

class CampaignBriefRepository extends BaseRepository
{
    protected $model;

    public function __construct()
    {
        $this->model = new CampaignBrief();
    }

    public function getByCampaignId(string $campaignId)
    {
        return $this->model->where('campaign_id', $this->normalizeId($campaignId))
            ->latest('created_at')
            ->first();
    }

    public function create(array $data)
    {
        return $this->model->create($data);
    }

    public function update(string $id, array $data)
    {
        $id = $this->normalizeId($id);
        $brief = $this->model->find($id);
        if ($brief) {
            $brief->update($data);
        }
        return $brief;
    }

    public function deleteByCampaignId(string $campaignId)
    {
        return $this->model->where('campaign_id', $this->normalizeId($campaignId))->delete();
    }
}
