<?php

namespace App\Services\Equipment;

use App\Entities\Equipment\PartEntity;
use App\Helpers\Equipment\PartHelper;
use App\Models\Equipment\PartModel;

class PartService extends EquipmentService
{
    public function __construct()
    {
        parent::__construct(new PartModel(), new PartHelper());
        $this->addClassName('Part');
    }
    public function getFormFields(): array
    {
        return [
            "type",
            "title",
            "price",
            "status",
        ];
    }
    public function getFormFilters(): array
    {
        return [
            'type',
            'status',
        ];
    }
    public function getIndexFields(): array
    {
        return [
            "type",
            "title",
            "price",
            "status",
        ];
    }
    public function getBatchjobFields(): array
    {
        return ['type', 'status'];
    }
    //기본 기능부분
    //FieldForm관련용
    //OrderBy 처리
    public function setOrderBy(mixed $field = null, mixed $value = null): void
    {
        $this->getModel()->orderBy('code ASC');
        parent::setOrderBy($field, $value);
    }

    public function create(array $formDatas): PartEntity
    {
        $entity = parent::create($formDatas);
        return $this->modify($entity, ['code' => $entity->getType() . $entity->getPK()]);
    }
}
