<?php

namespace backendApi\modules\v1\models;

use common\components\ActiveRecord;

/**
 * This is the model class for table "{{%ADMIN_COUNTRY}}".
 *
 * @property string $ID
 * @property string $ADMIN_ID 管理ID
 * @property string $COUNTRY_ID 国家ID
 * @property int $CREATED_AT 创建时间
 * @property int $UPDATED_AT 更新时间
 */
class AdminCountry extends ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%ADMIN_COUNTRY}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['ADMIN_ID', 'COUNTRY_ID'], 'required'],
            [['ID', 'ADMIN_ID', 'COUNTRY_ID'], 'string', 'max' => 50],
            [['ID'], 'unique'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'ID' => 'ID',
            'ADMIN_ID' => '管理ID',
            'COUNTRY_ID' => '国家ID',
            'CREATED_AT' => '创建时间',
            'UPDATED_AT' => '更新时间',
        ];
    }

    /**
     * @param $adminId
     * @return array
     */
    public static function getCountry($adminId): array
    {
        return self::find()->select('COUNTRY_ID')->where(['ADMIN_ID' => $adminId])->column();
    }
}
