<?php

namespace App\Swagger\v1;

/**
 * @OA\Tag(name="Model", description="모델(설계 상위) 관리")
 * @OA\Tag(name="ModelVersion", description="모델 버전(DRAFT/RELEASED) 관리")
 * @OA\Tag(name="BomTemplate", description="모델버전 기준 BOM 템플릿 관리")
 */

/* =========================
 * 공통 스키마 (설계 영역)
 * ========================= */

/**
 * @OA\Schema(
 *   schema="DesignModel",
 *   type="object",
 *   required={"id","tenant_id","code","name"},
 *
 *   @OA\Property(property="id", type="integer", example=101),
 *   @OA\Property(property="tenant_id", type="integer", example=1),
 *   @OA\Property(property="code", type="string", example="KSS01"),
 *   @OA\Property(property="name", type="string", example="KSS 표준 모델"),
 *   @OA\Property(property="category_id", type="integer", nullable=true, example=12),
 *   @OA\Property(property="lifecycle", type="string", nullable=true, example="ACTIVE"),
 *   @OA\Property(property="description", type="string", nullable=true, example="롤러 구조 표준 설계"),
 *   @OA\Property(property="is_active", type="boolean", example=true),
 *   @OA\Property(property="created_at", type="string", format="date-time", example="2025-09-05 10:11:12"),
 *   @OA\Property(property="updated_at", type="string", format="date-time", example="2025-09-05 10:11:12"),
 *   @OA\Property(property="deleted_at", type="string", format="date-time", nullable=true, example=null)
 * )
 *
 * @OA\Schema(
 *   schema="DesignModelPagination",
 *   type="object",
 *   description="라라벨 LengthAwarePaginator",
 *
 *   @OA\Property(property="current_page", type="integer", example=1),
 *   @OA\Property(property="data", type="array", @OA\Items(ref="#/components/schemas/DesignModel")),
 *   @OA\Property(property="first_page_url", type="string", example="/api/v1/design/models?page=1"),
 *   @OA\Property(property="from", type="integer", example=1),
 *   @OA\Property(property="last_page", type="integer", example=5),
 *   @OA\Property(property="last_page_url", type="string", example="/api/v1/design/models?page=5"),
 *   @OA\Property(property="links", type="array", @OA\Items(
 *     type="object",
 *     @OA\Property(property="url", type="string", nullable=true, example=null),
 *     @OA\Property(property="label", type="string", example="&laquo; Previous"),
 *     @OA\Property(property="active", type="boolean", example=false)
 *   )),
 *   @OA\Property(property="next_page_url", type="string", nullable=true, example="/api/v1/design/models?page=2"),
 *   @OA\Property(property="path", type="string", example="/api/v1/design/models"),
 *   @OA\Property(property="per_page", type="integer", example=20),
 *   @OA\Property(property="prev_page_url", type="string", nullable=true, example=null),
 *   @OA\Property(property="to", type="integer", example=20),
 *   @OA\Property(property="total", type="integer", example=92)
 * )
 *
 * @OA\Schema(
 *   schema="ModelVersion",
 *   type="object",
 *   required={"id","tenant_id","model_id","version_no","status"},
 *
 *   @OA\Property(property="id", type="integer", example=201),
 *   @OA\Property(property="tenant_id", type="integer", example=1),
 *   @OA\Property(property="model_id", type="integer", example=101),
 *   @OA\Property(property="version_no", type="integer", example=1),
 *   @OA\Property(property="status", type="string", example="RELEASED"),
 *   @OA\Property(property="effective_from", type="string", format="date-time", nullable=true, example="2025-09-05 11:00:00"),
 *   @OA\Property(property="effective_to", type="string", format="date-time", nullable=true, example=null),
 *   @OA\Property(property="notes", type="string", nullable=true, example="초도 릴리즈"),
 *   @OA\Property(property="is_active", type="boolean", example=true),
 *   @OA\Property(property="created_at", type="string", format="date-time"),
 *   @OA\Property(property="updated_at", type="string", format="date-time"),
 *   @OA\Property(property="deleted_at", type="string", format="date-time", nullable=true, example=null)
 * )
 *
 * @OA\Schema(
 *   schema="BomTemplate",
 *   type="object",
 *   required={"id","tenant_id","model_version_id","name"},
 *
 *   @OA\Property(property="id", type="integer", example=301),
 *   @OA\Property(property="tenant_id", type="integer", example=1),
 *   @OA\Property(property="model_version_id", type="integer", example=201),
 *   @OA\Property(property="name", type="string", example="Main"),
 *   @OA\Property(property="is_primary", type="boolean", example=true),
 *   @OA\Property(property="notes", type="string", nullable=true, example="표준 템플릿"),
 *   @OA\Property(property="items_count", type="integer", example=3, description="withCount(items) 사용 시"),
 *   @OA\Property(property="created_at", type="string", format="date-time"),
 *   @OA\Property(property="updated_at", type="string", format="date-time"),
 *   @OA\Property(property="deleted_at", type="string", format="date-time", nullable=true, example=null)
 * )
 *
 * @OA\Schema(
 *   schema="BomTemplateItem",
 *   type="object",
 *   required={"id","tenant_id","bom_template_id","ref_type","ref_id","qty"},
 *
 *   @OA\Property(property="id", type="integer", example=401),
 *   @OA\Property(property="tenant_id", type="integer", example=1),
 *   @OA\Property(property="bom_template_id", type="integer", example=301),
 *   @OA\Property(property="ref_type", type="string", example="MATERIAL", enum={"MATERIAL","PRODUCT"}),
 *   @OA\Property(property="ref_id", type="integer", example=10101),
 *   @OA\Property(property="qty", type="number", format="double", example=2.000000),
 *   @OA\Property(property="waste_rate", type="number", format="double", example=0.000000),
 *   @OA\Property(property="uom_id", type="integer", nullable=true, example=null),
 *   @OA\Property(property="notes", type="string", nullable=true, example="프레임용"),
 *   @OA\Property(property="sort_order", type="integer", example=10),
 *   @OA\Property(property="created_at", type="string", format="date-time"),
 *   @OA\Property(property="updated_at", type="string", format="date-time")
 * )
 *
 * @OA\Schema(
 *   schema="BomTemplateItemReplaceRequest",
 *   type="object",
 *   required={"items"},
 *
 *   @OA\Property(
 *     property="items",
 *     type="array",
 *
 *     @OA\Items(
 *       type="object",
 *       required={"ref_type","ref_id","qty"},
 *
 *       @OA\Property(property="ref_type", type="string", enum={"MATERIAL","PRODUCT"}, example="MATERIAL"),
 *       @OA\Property(property="ref_id", type="integer", example=101),
 *       @OA\Property(property="qty", type="number", format="double", example=2),
 *       @OA\Property(property="waste_rate", type="number", format="double", nullable=true, example=0),
 *       @OA\Property(property="uom_id", type="integer", nullable=true, example=null),
 *       @OA\Property(property="notes", type="string", nullable=true, example="프레임용"),
 *       @OA\Property(property="sort_order", type="integer", example=10)
 *     )
 *   )
 * )
 */

/* ================
 * 모델 엔드포인트
 * ================ */
class DesignModelApi
{
    /**
     * @OA\Get(
     *   path="/api/v1/design/models",
     *   tags={"Model"},
     *   summary="모델 목록",
     *   description="모델(설계 상위) 목록을 페이징으로 조회합니다.",
     *   security={{"ApiKeyAuth": {}},{"BearerAuth": {}}},
     *
     *   @OA\Parameter(name="q", in="query", description="검색어(code/name/description like)", @OA\Schema(type="string")),
     *   @OA\Parameter(ref="#/components/parameters/Page"),
     *   @OA\Parameter(ref="#/components/parameters/Size"),
     *
     *   @OA\Response(
     *     response=200, description="조회 성공",
     *
     *     @OA\JsonContent(
     *       allOf={
     *
     *         @OA\Schema(ref="#/components/schemas/ApiResponse"),
     *         @OA\Schema(@OA\Property(property="data", ref="#/components/schemas/DesignModelPagination"))
     *       }
     *     )
     *   ),
     *
     *   @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
     *   @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
     * )
     */
    public function index() {}

    /**
     * @OA\Post(
     *   path="/api/v1/design/models",
     *   tags={"Model"},
     *   summary="모델 생성",
     *   description="모델(설계 상위)을 생성합니다.",
     *   security={{"ApiKeyAuth": {}},{"BearerAuth": {}}},
     *
     *   @OA\RequestBody(
     *     required=true,
     *
     *     @OA\JsonContent(
     *       required={"code","name"},
     *
     *       @OA\Property(property="code", type="string", maxLength=100, example="KSS01"),
     *       @OA\Property(property="name", type="string", maxLength=200, example="KSS 표준 모델"),
     *       @OA\Property(property="category_id", type="integer", nullable=true, example=12),
     *       @OA\Property(property="lifecycle", type="string", nullable=true, example="ACTIVE"),
     *       @OA\Property(property="description", type="string", nullable=true, example="롤러 구조 표준 설계"),
     *       @OA\Property(property="is_active", type="boolean", example=true)
     *     )
     *   ),
     *
     *   @OA\Response(response=200, description="등록 성공", @OA\JsonContent(allOf={
     *
     *     @OA\Schema(ref="#/components/schemas/ApiResponse"),
     *     @OA\Schema(@OA\Property(property="data", ref="#/components/schemas/DesignModel"))
     *   })),
     *
     *   @OA\Response(response=422, description="검증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
     * )
     */
    public function store() {}

    /**
     * @OA\Get(
     *   path="/api/v1/design/models/{id}",
     *   tags={"Model"},
     *   summary="모델 상세",
     *   description="단일 모델을 조회합니다. (versions 포함 가능)",
     *   security={{"ApiKeyAuth": {}},{"BearerAuth": {}}},
     *
     *   @OA\Parameter(name="id", in="path", required=true, @OA\Schema(type="integer")),
     *
     *   @OA\Response(response=200, description="조회 성공", @OA\JsonContent(allOf={
     *
     *     @OA\Schema(ref="#/components/schemas/ApiResponse"),
     *     @OA\Schema(@OA\Property(property="data", ref="#/components/schemas/DesignModel"))
     *   })),
     *
     *   @OA\Response(response=404, description="없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
     * )
     */
    public function show() {}

    /**
     * @OA\Put(
     *   path="/api/v1/design/models/{id}",
     *   tags={"Model"},
     *   summary="모델 수정",
     *   security={{"ApiKeyAuth": {}},{"BearerAuth": {}}},
     *
     *   @OA\Parameter(name="id", in="path", required=true, @OA\Schema(type="integer")),
     *
     *   @OA\RequestBody(
     *     required=true,
     *
     *     @OA\JsonContent(
     *
     *       @OA\Property(property="code", type="string", maxLength=100, example="KSS01"),
     *       @OA\Property(property="name", type="string", maxLength=200, example="KSS 표준 모델(개정)"),
     *       @OA\Property(property="category_id", type="integer", nullable=true, example=12),
     *       @OA\Property(property="lifecycle", type="string", nullable=true, example="ACTIVE"),
     *       @OA\Property(property="description", type="string", nullable=true, example="개정 메모"),
     *       @OA\Property(property="is_active", type="boolean", example=true)
     *     )
     *   ),
     *
     *   @OA\Response(response=200, description="수정 성공", @OA\JsonContent(ref="#/components/schemas/ApiResponse")) ,
     *   @OA\Response(response=404, description="없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
     * )
     */
    public function update() {}

    /**
     * @OA\Delete(
     *   path="/api/v1/design/models/{id}",
     *   tags={"Model"},
     *   summary="모델 삭제(soft)",
     *   security={{"ApiKeyAuth": {}},{"BearerAuth": {}}},
     *
     *   @OA\Parameter(name="id", in="path", required=true, @OA\Schema(type="integer")),
     *
     *   @OA\Response(response=200, description="삭제 성공", @OA\JsonContent(ref="#/components/schemas/ApiResponse")),
     *   @OA\Response(response=404, description="없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
     * )
     */
    public function destroy() {}
}

/* ==================
 * 모델버전 엔드포인트
 * ================== */
class ModelVersionApi
{
    /**
     * @OA\Get(
     *   path="/api/v1/design/models/{modelId}/versions",
     *   tags={"ModelVersion"},
     *   summary="모델의 버전 목록",
     *   security={{"ApiKeyAuth": {}},{"BearerAuth": {}}},
     *
     *   @OA\Parameter(name="modelId", in="path", required=true, @OA\Schema(type="integer")),
     *
     *   @OA\Response(response=200, description="조회 성공",
     *
     *     @OA\JsonContent(allOf={
     *
     *       @OA\Schema(ref="#/components/schemas/ApiResponse"),
     *       @OA\Schema(@OA\Property(property="data", type="array", @OA\Items(ref="#/components/schemas/ModelVersion")))
     *     })
     *   ),
     *
     *   @OA\Response(response=404, description="없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
     * )
     */
    public function listVersions() {}

    /**
     * @OA\Post(
     *   path="/api/v1/design/models/{modelId}/versions",
     *   tags={"ModelVersion"},
     *   summary="버전 DRAFT 생성",
     *   description="version_no 미지정 시 자동 증가",
     *   security={{"ApiKeyAuth": {}},{"BearerAuth": {}}},
     *
     *   @OA\Parameter(name="modelId", in="path", required=true, @OA\Schema(type="integer")),
     *
     *   @OA\RequestBody(
     *     required=false,
     *
     *     @OA\JsonContent(
     *
     *       @OA\Property(property="version_no", type="integer", nullable=true, example=1),
     *       @OA\Property(property="notes", type="string", nullable=true, example="초안 메모"),
     *       @OA\Property(property="effective_from", type="string", format="date-time", nullable=true),
     *         @OA\Property(property="effective_to", type="string", format="date-time", nullable=true)
     *     )
     *   ),
     *
     *   @OA\Response(response=200, description="생성 성공",
     *
     *     @OA\JsonContent(allOf={
     *
     *       @OA\Schema(ref="#/components/schemas/ApiResponse"),
     *       @OA\Schema(@OA\Property(property="data", ref="#/components/schemas/ModelVersion"))
     *     })
     *   ),
     *
     *   @OA\Response(response=422, description="검증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
     * )
     */
    public function createDraft() {}

    /**
     * @OA\Post(
     *   path="/api/v1/design/versions/{versionId}/release",
     *   tags={"ModelVersion"},
     *   summary="버전 RELEASED 전환",
     *   security={{"ApiKeyAuth": {}},{"BearerAuth": {}}},
     *
     *   @OA\Parameter(name="versionId", in="path", required=true, @OA\Schema(type="integer")),
     *
     *   @OA\Response(response=200, description="전환 성공",
     *
     *     @OA\JsonContent(allOf={
     *
     *       @OA\Schema(ref="#/components/schemas/ApiResponse"),
     *       @OA\Schema(@OA\Property(property="data", ref="#/components/schemas/ModelVersion"))
     *     })
     *   ),
     *
     *   @OA\Response(response=409, description="상태 충돌", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
     *   @OA\Response(response=404, description="없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
     * )
     */
    public function release() {}
}

/* ===================
 * BOM 템플릿 엔드포인트
 * =================== */
class BomTemplateApi
{
    /**
     * @OA\Get(
     *   path="/api/v1/design/versions/{versionId}/bom-templates",
     *   tags={"BomTemplate"},
     *   summary="모델버전의 BOM 템플릿 목록",
     *   security={{"ApiKeyAuth": {}},{"BearerAuth": {}}},
     *
     *   @OA\Parameter(name="versionId", in="path", required=true, @OA\Schema(type="integer")),
     *
     *   @OA\Response(response=200, description="조회 성공",
     *
     *     @OA\JsonContent(allOf={
     *
     *       @OA\Schema(ref="#/components/schemas/ApiResponse"),
     *       @OA\Schema(@OA\Property(property="data", type="array", @OA\Items(ref="#/components/schemas/BomTemplate")))
     *     })
     *   ),
     *
     *   @OA\Response(response=404, description="없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
     * )
     */
    public function listByVersion() {}

    /**
     * @OA\Post(
     *   path="/api/v1/design/versions/{versionId}/bom-templates",
     *   tags={"BomTemplate"},
     *   summary="BOM 템플릿 upsert (name 기준)",
     *   description="is_primary=true 지정 시 동일 모델버전의 기존 대표 템플릿은 자동 해제",
     *   security={{"ApiKeyAuth": {}},{"BearerAuth": {}}},
     *
     *   @OA\Parameter(name="versionId", in="path", required=true, @OA\Schema(type="integer")),
     *
     *   @OA\RequestBody(
     *     required=false,
     *
     *     @OA\JsonContent(
     *
     *       @OA\Property(property="name", type="string", maxLength=100, example="Main"),
     *       @OA\Property(property="is_primary", type="boolean", example=true),
     *       @OA\Property(property="notes", type="string", nullable=true, example="표준 템플릿")
     *     )
     *   ),
     *
     *   @OA\Response(response=200, description="저장 성공",
     *
     *     @OA\JsonContent(allOf={
     *
     *       @OA\Schema(ref="#/components/schemas/ApiResponse"),
     *       @OA\Schema(@OA\Property(property="data", ref="#/components/schemas/BomTemplate"))
     *     })
     *   ),
     *
     *   @OA\Response(response=422, description="검증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
     * )
     */
    public function upsertTemplate() {}

    /**
     * @OA\Get(
     *   path="/api/v1/design/bom-templates/{templateId}",
     *   tags={"BomTemplate"},
     *   summary="BOM 템플릿 상세 (항목 포함)",
     *   security={{"ApiKeyAuth": {}},{"BearerAuth": {}}},
     *
     *   @OA\Parameter(name="templateId", in="path", required=true, @OA\Schema(type="integer")),
     *
     *   @OA\Response(response=200, description="조회 성공",
     *
     *     @OA\JsonContent(allOf={
     *
     *       @OA\Schema(ref="#/components/schemas/ApiResponse"),
     *       @OA\Schema(@OA\Property(property="data", ref="#/components/schemas/BomTemplate"))
     *     })
     *   ),
     *
     *   @OA\Response(response=404, description="없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
     * )
     */
    public function show() {}

    /**
     * @OA\Put(
     *   path="/api/v1/design/bom-templates/{templateId}/items",
     *   tags={"BomTemplate"},
     *   summary="BOM 항목 일괄 치환",
     *   description="기존 항목을 모두 삭제 후 본문 items로 재삽입",
     *   security={{"ApiKeyAuth": {}},{"BearerAuth": {}}},
     *
     *   @OA\Parameter(name="templateId", in="path", required=true, @OA\Schema(type="integer")),
     *
     *   @OA\RequestBody(required=true, @OA\JsonContent(ref="#/components/schemas/BomTemplateItemReplaceRequest")),
     *
     *   @OA\Response(response=200, description="저장 성공", @OA\JsonContent(ref="#/components/schemas/ApiResponse")),
     *   @OA\Response(response=422, description="검증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
     * )
     */
    public function replaceItems() {}
}
