<?php

use Jaga\Models\BaseModel;
use Jaga\Traits\JagaTimestamp;
use Jaga\Traits\SoftDelete;

class PancekKomponenTemplate extends BaseModel
{
    use JagaTimestamp, SoftDelete;

    public $id;
    public $komponen_indikator_id;
    public $attachment_id;
    public $label;
    public $created_at;
    public $updated_at;
    public $deleted_at;
    public $language;

    public static $throwableModelName = 'Template Komponen PanCek';

    const DOCUMENT_DIR = "pancek-komponen-template";

    public function initialize()
    {
        $this->setSchema("jaga");
        $this->setSource("pancek_komponen_template");
        $this->belongsTo(
            "komponen_indikator_id",
            \PancekKomponenIndikator::class,
            "id",
            [
                'reusable' => true, // cache related data
                'alias'    => 'komponenIndikator',
            ]
        );
        $this->belongsTo(
            "attachment_id",
            \Attachments::class,
            "id",
            [
                'reusable' => true, // cache related data
                'alias'    => 'attachment',
            ]
        );
    }

    public function toArray($columns = null)
    {
        return parent::toArray($columns);
    }

    public function getDetail($columns = null)
    {
        $result = $this->toArray($columns);

        $result['file'] = $this->attachment->toArray(['id','uuid','filename']);

        return $result;
    }
}
