<script setup lang="ts">
import { computed } from 'vue'
import type { ResearchSellPolicyResponse } from '../schema'

type TraceEntry = ResearchSellPolicyResponse['policyTrace'][number]
const props = defineProps<{ entries: TraceEntry[]; schemaVersion: 2 }>()
const dispositionLabel: Record<0 | 1 | 2, string> = { 0: 'NOT_APPLICABLE', 1: 'BLOCKED', 2: 'APPLIED' }
const ordered = computed(() => [...props.entries].sort((a, b) => b.priority - a.priority))
</script>

<template>
  <section aria-labelledby="policy-trace-title">
    <h2 id="policy-trace-title">정책 우선순위 추적</h2>
    <p>Trace schema v{{ props.schemaVersion }} · 상위 정책부터 평가된 불변 증거입니다.</p>
    <ol>
      <li v-for="entry in ordered" :key="`${entry.priority}-${entry.policyId}`">
        <strong>{{ entry.policyId }}</strong>
        <span> {{ dispositionLabel[entry.disposition] }} · {{ entry.reasonCode }}</span>
        <span v-if="entry.requestedSellRatioOfLot > 0">
          · 요청 {{ entry.requestedSellRatioOfLot }} / 적용 {{ entry.appliedSellRatioOfLot }}
        </span>
        <span v-if="entry.strategicCoreClampApplied"> · Strategic Core clamp</span>
      </li>
    </ol>
  </section>
</template>
