<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class AdCampaign extends Model
{
    use HasFactory;

    protected $table = 'ad_campaigns';

    protected $fillable = [
        'customer_id',
        'created_by_user_id',
        'facebook_integration_id', // Keep for backward compatibility or relationship
        'campaign_id',
        'campaign_name',
        'objective',
        'budget_type',
        'budget_amount',
        'start_date',
        'end_date',
        'country',
        'city',
        'age_from',
        'age_to',
        'gender',
        'interests',
        'language',
        'placements_type',
        'placements',
        'headline',
        'primary_text',
        'description',
        'cta',
        'destination_url',
        'media_type',
        'media_path',
        'post_id',
        'meta_campaign_id',
        'meta_adset_id',
        'meta_creative_id',
        'meta_ad_id',
        'launch_status',
        'sync_error',
        'status',
    ];

    protected $casts = [
        'start_date' => 'datetime',
        'end_date' => 'datetime',
        'interests' => 'array',
        'placements' => 'array',
    ];

    public function customer()
    {
        return $this->belongsTo(Customer::class);
    }

    public function creator()
    {
        return $this->belongsTo(User::class, 'created_by_user_id');
    }

    public function reports()
    {
        return $this->hasMany(AdCampaignReport::class);
    }

    public function facebookIntegration()
    {
        return $this->belongsTo(FacebookIntegration::class);
    }

    public function adSets()
    {
        return $this->hasMany(AdSet::class, 'ad_campaign_id');
    }
}
