// Copyright (c) 2026 Hellmai Ltd
// SPDX-License-Identifier: AGPL-3.0-only

import {
  DomainPackManifestSchema,
  POLICY_TRIGGERS,
  type DomainPackManifest,
  type DomainPackTool,
} from '@lumenflow/kernel';
import type { PathScope, ToolPermission } from './tools/types.js';

interface Parser<T> {
  parse(input: unknown): T;
}

export const MANIFEST_POLICY_TRIGGERS = POLICY_TRIGGERS;

export type ManifestPolicyTrigger =
  (typeof MANIFEST_POLICY_TRIGGERS)[keyof typeof MANIFEST_POLICY_TRIGGERS];

export const MANIFEST_POLICY_DECISIONS = {
  ALLOW: 'allow',
  DENY: 'deny',
  APPROVAL_REQUIRED: 'approval_required',
} as const;

export type ManifestPolicyDecision =
  (typeof MANIFEST_POLICY_DECISIONS)[keyof typeof MANIFEST_POLICY_DECISIONS];

export interface SidekickManifestTool extends Omit<
  DomainPackTool,
  'permission' | 'required_scopes'
> {
  permission: ToolPermission;
  required_scopes: PathScope[];
}

export type SidekickManifestPolicy = DomainPackManifest['policies'][number];

export interface SidekickPackManifest extends Omit<DomainPackManifest, 'tools' | 'policies'> {
  tools: SidekickManifestTool[];
  policies: SidekickManifestPolicy[];
}

export const SidekickManifestSchema: Parser<SidekickPackManifest> = {
  parse(input: unknown): SidekickPackManifest {
    return DomainPackManifestSchema.parse(input) as SidekickPackManifest;
  },
};
