<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use OpenApi\Attributes as OA;

#[OA\Info(
    version: '1.0.0',
    title: 'YAAME API',
    description: 'YAAME Super-App REST API — powers the customer and vendor mobile applications. All protected endpoints require a Bearer token obtained from POST /api/auth/login.',
    contact: new OA\Contact(email: 'api@yaame.com', name: 'YAAME Dev Team'),
    license: new OA\License(name: 'Proprietary', url: 'https://yaame.com')
)]
#[OA\Server(url: L5_SWAGGER_CONST_HOST, description: 'Development Server')]
#[OA\SecurityScheme(
    securityScheme: 'passport',
    type: 'http',
    scheme: 'bearer',
    bearerFormat: 'JWT',
    description: 'Enter the access_token returned from the login API.',
)]
#[OA\Tag(name: 'Auth',     description: 'User registration, login, logout, and OTP verification')]
#[OA\Tag(name: 'Customer', description: 'Authenticated customer profile and order history')]
#[OA\Tag(name: 'Vendor',   description: 'Authenticated vendor profile, orders, and ad upload')]
#[OA\Tag(name: 'Orders',   description: 'Place and track orders (ride / food / delivery / freelance)')]
#[OA\Tag(name: 'Wallet',   description: 'Wallet balance, transaction history, and withdrawal requests')]
#[OA\Tag(name: 'Ads',      description: 'Browse approved vendor advertisements')]

// ─── Reusable Schemas ─────────────────────────────────────────────────────────

#[OA\Schema(
    schema: 'UserResource',
    properties: [
        new OA\Property(property: 'id',         type: 'integer',  example: 1),
        new OA\Property(property: 'name',       type: 'string',   example: 'Ronio Doe'),
        new OA\Property(property: 'email',      type: 'string',   format: 'email', example: 'ronio@example.com'),
        new OA\Property(property: 'phone',      type: 'string',   example: '+2348012345678'),
        new OA\Property(property: 'status',     type: 'string',   enum: ['active', 'pending', 'blocked', 'suspended', 'rejected'], example: 'active'),
        new OA\Property(property: 'created_at', type: 'string',   format: 'date-time'),
    ],
    type: 'object'
)]
#[OA\Schema(
    schema: 'TokenResponse',
    properties: [
        new OA\Property(property: 'message', type: 'string',  example: 'Login successful.'),
        new OA\Property(property: 'token',   type: 'string',  example: '1|abc123xyz...'),
        new OA\Property(property: 'user',    ref: '#/components/schemas/UserResource'),
    ],
    type: 'object'
)]
#[OA\Schema(
    schema: 'OrderItem',
    required: ['name', 'price', 'quantity'],
    properties: [
        new OA\Property(property: 'name',     type: 'string',  example: 'Jollof Rice'),
        new OA\Property(property: 'price',    type: 'number',  format: 'float', example: 1500.00),
        new OA\Property(property: 'quantity', type: 'integer', example: 2),
        new OA\Property(property: 'options',  type: 'object',  nullable: true),
    ],
    type: 'object'
)]
#[OA\Schema(
    schema: 'OrderResource',
    properties: [
        new OA\Property(property: 'id',               type: 'integer'),
        new OA\Property(property: 'reference',         type: 'string',  example: 'ORD-ABC123'),
        new OA\Property(property: 'type',              type: 'string',  enum: ['ride', 'food', 'delivery', 'freelance']),
        new OA\Property(property: 'status',            type: 'string',  enum: ['pending', 'accepted', 'in_progress', 'completed', 'cancelled', 'disputed']),
        new OA\Property(property: 'payment_method',    type: 'string',  enum: ['wallet', 'cash', 'card']),
        new OA\Property(property: 'payment_status',    type: 'string',  enum: ['unpaid', 'paid', 'refunded']),
        new OA\Property(property: 'subtotal',          type: 'number',  format: 'float'),
        new OA\Property(property: 'commission',        type: 'number',  format: 'float'),
        new OA\Property(property: 'total',             type: 'number',  format: 'float'),
        new OA\Property(property: 'pickup_address',    type: 'string',  nullable: true),
        new OA\Property(property: 'delivery_address',  type: 'string',  nullable: true),
        new OA\Property(property: 'notes',             type: 'string',  nullable: true),
        new OA\Property(property: 'created_at',        type: 'string',  format: 'date-time'),
        new OA\Property(property: 'items', type: 'array', items: new OA\Items(ref: '#/components/schemas/OrderItem')),
    ],
    type: 'object'
)]
#[OA\Schema(
    schema: 'WalletResource',
    properties: [
        new OA\Property(property: 'id',                 type: 'integer'),
        new OA\Property(property: 'balance',            type: 'number', format: 'float', example: 5000.00),
        new OA\Property(property: 'points',             type: 'number', format: 'float', example: 120.00),
        new OA\Property(property: 'pending_withdrawal', type: 'number', format: 'float', example: 0.00),
        new OA\Property(property: 'currency',           type: 'string', example: 'NGN'),
        new OA\Property(property: 'owner_type',         type: 'string', example: 'App\\Models\\User'),
        new OA\Property(property: 'owner_id',           type: 'integer'),
    ],
    type: 'object'
)]
#[OA\Schema(
    schema: 'WalletTransactionResource',
    properties: [
        new OA\Property(property: 'id',             type: 'integer'),
        new OA\Property(property: 'reference',      type: 'string',  example: 'WDR-XYZ001'),
        new OA\Property(property: 'type',           type: 'string',  enum: ['credit', 'debit', 'withdrawal', 'refund', 'bonus', 'commission']),
        new OA\Property(property: 'amount',         type: 'number',  format: 'float', example: 1000.00),
        new OA\Property(property: 'balance_before', type: 'number',  format: 'float'),
        new OA\Property(property: 'balance_after',  type: 'number',  format: 'float'),
        new OA\Property(property: 'status',         type: 'string',  enum: ['pending', 'completed', 'failed', 'cancelled']),
        new OA\Property(property: 'description',    type: 'string',  nullable: true),
        new OA\Property(property: 'created_at',     type: 'string',  format: 'date-time'),
    ],
    type: 'object'
)]
#[OA\Schema(
    schema: 'AdResource',
    properties: [
        new OA\Property(property: 'id',          type: 'integer'),
        new OA\Property(property: 'title',       type: 'string',  example: 'Summer Sale'),
        new OA\Property(property: 'description', type: 'string',  nullable: true),
        new OA\Property(property: 'type',        type: 'string',  enum: ['banner', 'video']),
        new OA\Property(property: 'media_url',   type: 'string',  example: 'ads/banner123.jpg'),
        new OA\Property(property: 'link_url',    type: 'string',  nullable: true),
        new OA\Property(property: 'impressions', type: 'integer'),
        new OA\Property(property: 'clicks',      type: 'integer'),
        new OA\Property(property: 'expires_at',  type: 'string',  format: 'date-time', nullable: true),
    ],
    type: 'object'
)]
#[OA\Schema(
    schema: 'VendorResource',
    properties: [
        new OA\Property(property: 'id',            type: 'integer'),
        new OA\Property(property: 'business_name', type: 'string',  example: 'Mama Put Kitchen'),
        new OA\Property(property: 'description',   type: 'string',  nullable: true),
        new OA\Property(property: 'phone',         type: 'string',  nullable: true),
        new OA\Property(property: 'address',       type: 'string',  nullable: true),
        new OA\Property(property: 'status',        type: 'string',  enum: ['active', 'pending', 'blocked', 'suspended', 'rejected']),
        new OA\Property(property: 'kyc_status',    type: 'string',  enum: ['pending', 'approved', 'rejected']),
        new OA\Property(property: 'rating',        type: 'number',  format: 'float', example: 4.5),

    ],
    type: 'object'
)]
#[OA\Schema(
    schema: 'ValidationError',
    properties: [
        new OA\Property(property: 'message', type: 'string', example: 'The given data was invalid.'),
        new OA\Property(
            property: 'errors',
            type: 'object',
            additionalProperties: new OA\AdditionalProperties(type: 'array', items: new OA\Items(type: 'string'))
        ),
    ],
    type: 'object'
)]
#[OA\Schema(
    schema: 'UnauthorizedError',
    properties: [
        new OA\Property(property: 'message', type: 'string', example: 'Unauthenticated.'),
    ],
    type: 'object'
)]
#[OA\Schema(
    schema: 'PaginationMeta',
    properties: [
        new OA\Property(property: 'current_page', type: 'integer'),
        new OA\Property(property: 'last_page',    type: 'integer'),
        new OA\Property(property: 'per_page',     type: 'integer'),
        new OA\Property(property: 'total',        type: 'integer'),
    ],
    type: 'object'
)]
class ApiController extends Controller {}
