<?php

namespace app\model;

use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\model\relation\HasMany;
use think\model\relation\HasOne;

class Archives extends Base
{
    public const ORIGINAL_TABLE = 'bee_archives';

    public const STATUS_NORMAL  = 1;//正常
    public const STATUS_DISABLE = 0;//禁用

    /**
     * 相关记录 点赞|收藏
     *
     * @return HasMany
     */
    public function record(): HasMany
    {
        return $this->hasMany(AccountRecord::class, 'relation_id', 'id');
    }

    /**
     * 是否收藏
     *
     * @return HasOne
     */
    public function collect(): HasOne
    {
        return $this->hasOne(AccountRecord::class, 'relation_id', 'id')->bind(['is_collected' => 'is_record']);
    }

    /**
     * 创建人信息
     *
     * @return HasOne
     */
    public function member(): HasOne
    {
        return $this->hasOne(Member::class, 'id', 'created_by')->bind(['nickname']);
    }


    /**
     * 分类
     *
     * @return HasOne
     */
    public function category(): HasOne
    {
        return $this->hasOne(ArchivesCategory::class, 'id', 'category_id')->bind(['category_title' => 'title']);
    }
}