<?php

namespace App\Models;

/**
 * TrashItemVo - 回收站项目视图对象
 * 用于返回回收站中的笔记或分组信息
 */
class TrashItemVo
{
    /**
     * @var string 项目ID
     */
    public $id;

    /**
     * @var string 项目名称（笔记标题或分组名称）
     */
    public $title;

    /**
     * @var string 项目类型（note 或 group）
     */
    public $type;

    /**
     * @var string 删除时间（格式：yyyy-MM-dd HH:mm:ss）
     */
    public $deletedAt;

    /**
     * @var string 删除者ID
     */
    public $deletedBy;

    /**
     * 构造函数
     * @param string $id 项目ID
     * @param string $title 项目名称
     * @param string $type 项目类型（note 或 group）
     * @param string $deletedAt 删除时间
     * @param string $deletedBy 删除者ID
     */
    public function __construct($id = '', $title = '', $type = '', $deletedAt = '', $deletedBy = '')
    {
        $this->id = $id;
        $this->title = $title;
        $this->type = $type;
        $this->deletedAt = $deletedAt;
        $this->deletedBy = $deletedBy;
    }

    /**
     * 将对象转换为数组
     * @return array
     */
    public function toArray()
    {
        return [
            'id' => $this->id,
            'title' => $this->title,
            'type' => $this->type,
            'deletedAt' => $this->deletedAt,
            'deletedBy' => $this->deletedBy,
        ];
    }

    /**
     * 从数组创建对象
     * @param array $data
     * @return TrashItemVo
     */
    public static function fromArray($data)
    {
        return new self(
            $data['id'] ?? '',
            $data['title'] ?? '',
            $data['type'] ?? '',
            $data['deletedAt'] ?? '',
            $data['deletedBy'] ?? ''
        );
    }
}
