<?php

namespace app\model;

use think\Model;

class Ad extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'bps_google_ads_ad';

    // 设置主键
    protected $pk = 'ad_id';

    // 设置自动时间戳
    protected $autoWriteTimestamp = true;

    // 定义时间戳字段
    protected $createTime = 'create_at';
    protected $updateTime = 'update_at';

    // 设置字段类型和默认值
    protected $casts = [
        'ad_id' => 'int',
        'ad_group_id' => 'int',
        'customer_id' => 'int',
    ];

    // 默认值设置
    protected $defaults = [
        'status' => 'ENABLED', // 广告状态默认值为 'ENABLED'
    ];

    // 关联 AdGroup 模型(广告属于广告组)
    // 即使没有外键约束,依然可以使用 belongsTo 访问 AdGroup 数据
    public function adGroup()
    {
        return $this->belongsTo(AdGroup::class, 'ad_group_id', 'ad_group_id');
    }

    // 关联 Customer 模型(广告属于客户)
//    public function customer()
//    {
//        return $this->belongsTo(GoogleAdsCustomer::class, 'customer_id', 'customer_id');
//    }
}