import { defineCollection, z } from 'astro:content';
import { glob } from 'astro/loaders';

// =============================================================================
// SERVICES — service detail pages
// =============================================================================
const services = defineCollection({
  loader: glob({ pattern: '**/*.{md,mdx}', base: './src/content/services' }),
  schema: z.object({
    title: z.string(),
    subtitle: z.string(),
    badge: z.string(),
    category: z.string(),
    objective: z.string(),
    short_desc: z.string().optional(), // NEW: short description
    usp_free_server: z.string().optional(),
    usp_content_edit: z.string().optional(),
  }),
});

// =============================================================================
// PORTFOLIO — client work
// =============================================================================
const portfolio = defineCollection({
  loader: glob({ pattern: '**/*.{md,mdx}', base: './src/content/portfolio' }),
  schema: z.object({
    name: z.string(),
    url: z.string().optional(),
    category: z.string(), // webdev | ecommerce | marketing | ai-consult | automation
    category_label: z.string(),
    industry: z.string().optional(), // industry for filtering
    thumbnail: z.string().optional(), // optional now
    description: z.string().optional(),
    what_we_did: z.string().optional(),
    result: z.string().optional(),
    featured: z.boolean().optional(), // NEW: show on home page
    order: z.number().optional(), // NEW: display order
    case_study: z.boolean().optional(), // NEW: full case study body
  }),
});

// =============================================================================
// PAGES — static page content (about, home, etc.)
// =============================================================================
const pages = defineCollection({
  loader: glob({ pattern: '*.{md,mdx}', base: './src/content/pages' }),
  schema: z.object({
    title: z.string().optional(),
    subtitle: z.string().optional(),
    hero_badge: z.string().optional(),
    badge: z.string().optional(),
  }),
});

// =============================================================================
// FAQ
// =============================================================================
const faq = defineCollection({
  loader: glob({ pattern: '**/*.{md,mdx}', base: './src/content/faq' }),
  schema: z.object({
    category: z.string(),
    category_icon: z.string().optional(),
    question: z.string(),
    answer: z.string(),
  }),
});

// =============================================================================
// SETTINGS — site identity & contact
// =============================================================================
const settings = defineCollection({
  loader: glob({ pattern: '**/*.{md,mdx}', base: './src/content/settings' }),
  schema: z.object({
    site_name: z.string().optional(),
    email: z.string().optional(),
    phone: z.string().optional(),
    address: z.string().optional(),
    facebook: z.string().optional(),
    line: z.string().optional(),
    linkedin: z.string().optional(),
    line_id: z.string().optional(),
  }),
});

// =============================================================================
// BLOG (existing)
// =============================================================================
const blog = defineCollection({
  loader: glob({ pattern: '**/*.{md,mdx}', base: './src/content/blog' }),
  schema: z.object({
    title: z.string(),
    excerpt: z.string(),
    image: z.string(),
    date: z.date(),
    category: z.string(),
  }),
});

export const collections = {
  services,
  portfolio,
  faq,
  settings,
  blog,
  pages,
};
