<?php

namespace app\manager\model;

use think\Model;

class ActivationCode extends Model
{
    protected $name = 'cursor_activation_codes';
    
    // 自动写入时间戳
    protected $autoWriteTimestamp = true;
    protected $createTime = 'created_at';
    protected $updateTime = false;

    // 设置字段类型
    protected $type = [
        'used_at' => 'datetime',
        'created_at' => 'datetime',
    ];

    // 获取代理商分配信息
    public function agentCode()
    {
        return $this->hasOne('app\manager\model\AgentCode', 'code_id');
    }

    // 检查是否已分配给代理商
    public function isAssigned()
    {
        return (bool)$this->agentCode;
    }

    // 检查是否可用
    public function isAvailable()
    {
        return !$this->is_used && !$this->isAssigned();
    }
} 