{
  "name": "Team",
  "label": "Team",
  "description": "Team structure and information storage",
  "tags": ["team", "structure", "business", "verification"],
  "table": {
    "name": "team",
    "comment": "Team structure and information storage"
  },
  "columns": [
    // ============================================================================
    // Basic Fields
    // ============================================================================
    {
      "name": "id",
      "type": "ID",
      "label": "ID",
      "comment": "Primary key identifier",
      "primary": true
    },
    {
      "name": "team_id",
      "type": "string",
      "label": "Team ID",
      "comment": "Global unique team identifier",
      "length": 255,
      "unique": true,
      "index": true
    },

    // ============================================================================
    // Team Basic Information
    // ============================================================================
    {
      "name": "name",
      "type": "string",
      "label": "Team Name",
      "comment": "Official team name",
      "length": 200,
      "nullable": false
    },
    {
      "name": "display_name",
      "type": "string",
      "label": "Display Name",
      "comment": "Team display name or brand name",
      "length": 200,
      "nullable": true
    },
    {
      "name": "description",
      "type": "text",
      "label": "Description",
      "comment": "Team description",
      "nullable": true
    },
    {
      "name": "website",
      "type": "string",
      "label": "Website",
      "comment": "Team website URL",
      "length": 500,
      "nullable": true
    },
    {
      "name": "logo",
      "type": "string",
      "label": "Logo",
      "comment": "Team logo URL",
      "length": 500,
      "nullable": true
    },

    // ============================================================================
    // Team Ownership
    // ============================================================================
    {
      "name": "owner_id",
      "type": "string",
      "label": "Owner ID",
      "comment": "Team owner user identifier (references user.user_id)",
      "length": 255,
      "nullable": false,
      "index": true
    },

    // ============================================================================
    // Contact Information (Optional)
    // ============================================================================
    {
      "name": "contact_email",
      "type": "string",
      "label": "Contact Email",
      "comment": "Team contact email address",
      "length": 255,
      "nullable": true,
      "index": true
    },
    {
      "name": "contact_phone",
      "type": "string",
      "label": "Contact Phone",
      "comment": "Team contact phone number",
      "length": 50,
      "nullable": true,
      "index": true
    },

    // ============================================================================
    // Team Verification
    // ============================================================================
    {
      "name": "is_verified",
      "type": "boolean",
      "label": "Is Verified",
      "comment": "Whether team is verified",
      "default": false,
      "index": true
    },
    {
      "name": "verified_at",
      "type": "timestamp",
      "label": "Verified At",
      "comment": "When team was verified",
      "nullable": true,
      "index": true
    },
    {
      "name": "verified_by",
      "type": "string",
      "label": "Verified By",
      "comment": "Who verified this team",
      "length": 255,
      "nullable": true
    },

    // ============================================================================
    // Team Unique Code & Type
    // ============================================================================
    {
      "name": "team_code",
      "type": "string",
      "label": "Team Code",
      "comment": "Unique team identification code",
      "length": 100,
      "nullable": true,
      "unique": true,
      "index": true
    },
    {
      "name": "team_code_type",
      "type": "enum",
      "label": "Team Code Type",
      "comment": "Type of team identification code",
      "option": [
        // ============================================================================
        // Global Universal Standards (Apple & International Compatible)
        // ============================================================================
        "DUNS", // Dun & Bradstreet Universal Numbering System (Apple Required)
        "LEI", // Legal Entity Identifier (Global Financial Standard)
        "GS1", // Global Standards One Company Prefix

        // ============================================================================
        // North America
        // ============================================================================
        "EIN", // US Employer Identification Number
        "SSN", // US Social Security Number (for sole proprietors)
        "ITIN", // US Individual Taxpayer Identification Number
        "BN", // Canada Business Number
        "NAICS", // North American Industry Classification System
        "SIC", // Standard Industrial Classification

        // ============================================================================
        // European Union & Europe
        // ============================================================================
        "VAT", // Value Added Tax Number (EU-wide)
        "EORI", // Economic Operators Registration and Identification (EU)
        "NACE", // European Statistical Classification of Economic Activities
        "CRN", // Company Registration Number (UK)
        "UTR", // Unique Taxpayer Reference (UK)
        "SIREN", // French Business Identification (9 digits)
        "SIRET", // French Establishment Identification (14 digits)
        "KVK", // Netherlands Chamber of Commerce Number
        "HRB", // German Commercial Register Number
        "UID", // Austrian/Swiss VAT Identification Number
        "ORG_NR", // Norwegian Organization Number
        "CVR", // Danish Central Business Register
        "Y_TUNNUS", // Finnish Business ID
        "ORG_NR_SE", // Swedish Organization Number
        "CIF", // Spain Tax Identification Code
        "NIF", // Portugal/Spain Tax Identification Number
        "REGON", // Poland National Business Registry
        "NIP", // Poland Tax Identification Number
        "INN", // Russia Tax Identification Number
        "OGRN", // Russia Primary State Registration Number
        "KPP", // Russia Tax Registration Reason Code

        // ============================================================================
        // Asia Pacific
        // ============================================================================
        "ABN", // Australian Business Number
        "ACN", // Australian Company Number
        "NZBN", // New Zealand Business Number
        "BRN", // Singapore Business Registration Number
        "UEN", // Singapore Unique Entity Number
        "ACRA", // Singapore Accounting and Corporate Regulatory Authority
        "GST_IN", // India Goods and Services Tax Number
        "PAN", // India Permanent Account Number
        "CIN", // India Corporate Identity Number
        "TAN", // India Tax Deduction Account Number
        "HKBR", // Hong Kong Business Registration Number
        "CR_NO", // Hong Kong Company Registration Number
        "BUSINESS_CODE_JP", // Japan Corporate Number
        "HOJIN_NO", // Japan Legal Person Number
        "BRN_KR", // South Korea Business Registration Number
        "CRN_KR", // South Korea Corporate Registration Number

        // ============================================================================
        // Latin America
        // ============================================================================
        "CNPJ", // Brazil National Registry of Legal Entities
        "CPF", // Brazil Individual Taxpayer Registry
        "RUC_PE", // Peru Tax Registry
        "RUC_EC", // Ecuador Tax Registry
        "RUT_CL", // Chile Tax Registry
        "RUT_UY", // Uruguay Tax Registry
        "CUIT", // Argentina Tax ID
        "RIF", // Venezuela Tax Registry
        "NIT_CO", // Colombia Tax ID
        "RFC", // Mexico Tax Registry

        // ============================================================================
        // Middle East & Africa
        // ============================================================================
        "TRN", // UAE Tax Registration Number
        "CR_SA", // Saudi Arabia Commercial Registration
        "VAT_SA", // Saudi Arabia VAT Number
        "TIN_ZA", // South Africa Tax Reference Number
        "CK_ZA", // South Africa Company Registration Number

        // ============================================================================
        // Generic & Others
        // ============================================================================
        "TIN", // Tax Identification Number (Generic)
        "GST", // Goods and Services Tax Number (Generic)
        "BUSINESS_LICENSE", // Business License Number (Generic)
        "TRADE_LICENSE", // Trade License Number (Generic)
        "OTHER" // Other/Custom code type
      ],
      "nullable": true,
      "index": true
    },

    // ============================================================================
    // Team Status & Management
    // ============================================================================
    {
      "name": "status",
      "type": "enum",
      "label": "Status",
      "comment": "Team status",
      "option": [
        "pending", // New team awaiting verification
        "active", // Active team with full access
        "inactive", // Temporarily inactive
        "suspended", // Suspended due to policy violations
        "archived" // Archived team
      ],
      "default": "pending",
      "index": true,
      "nullable": false
    },
    {
      "name": "role_id",
      "type": "string",
      "label": "Role ID",
      "comment": "Team owner role identifier (references role.role_id)",
      "length": 50,
      "nullable": true,
      "index": true
    },
    {
      "name": "type_id",
      "type": "string",
      "label": "Type ID",
      "comment": "Team type identifier for limits and permissions (references user.type.type_id)",
      "length": 50,
      "nullable": true,
      "index": true
    },
    {
      "name": "type",
      "type": "enum",
      "label": "Team Type",
      "comment": "Type of team",
      "option": [
        "corporation",
        "llc",
        "partnership",
        "sole_proprietorship",
        "nonprofit",
        "government",
        "educational",
        "other"
      ],
      "nullable": true,
      "index": true
    },

    // ============================================================================
    // Address Information
    // ============================================================================
    {
      "name": "address",
      "type": "json",
      "label": "Address",
      "comment": "Team physical address (structured JSON with full details)",
      "nullable": true
    },
    {
      "name": "street_address",
      "type": "string",
      "label": "Street Address",
      "comment": "Street address line (for quick access and indexing)",
      "length": 500,
      "nullable": true
    },
    {
      "name": "city",
      "type": "string",
      "label": "City",
      "comment": "Team city",
      "length": 100,
      "nullable": true,
      "index": true
    },
    {
      "name": "state_province",
      "type": "string",
      "label": "State/Province",
      "comment": "State, province, or administrative region",
      "length": 100,
      "nullable": true,
      "index": true
    },
    {
      "name": "postal_code",
      "type": "string",
      "label": "Postal Code",
      "comment": "ZIP code, postal code, or equivalent",
      "length": 20,
      "nullable": true,
      "index": true
    },
    {
      "name": "country",
      "type": "string",
      "label": "Country",
      "comment": "Team country (ISO 3166-1 alpha-2)",
      "length": 2,
      "nullable": true,
      "index": true
    },
    {
      "name": "country_name",
      "type": "string",
      "label": "Country Name",
      "comment": "Full country name for display",
      "length": 100,
      "nullable": true
    },
    {
      "name": "region",
      "type": "string",
      "label": "Region",
      "comment": "Geographic region (e.g., North America, Europe, Asia-Pacific)",
      "length": 50,
      "nullable": true,
      "index": true
    },
    {
      "name": "zoneinfo",
      "type": "string",
      "label": "Zone Info",
      "comment": "Team primary timezone (IANA Time Zone Database format)",
      "length": 50,
      "nullable": true,
      "index": true
    },

    // ============================================================================
    // Team Settings
    // ============================================================================
    {
      "name": "settings",
      "type": "json",
      "label": "Settings",
      "comment": "Team configuration settings",
      "nullable": true
    },
    {
      "name": "metadata",
      "type": "json",
      "label": "Metadata",
      "comment": "Extended team metadata and custom fields",
      "nullable": true
    }
  ],
  "indexes": [
    {
      "name": "idx_team_owner_status",
      "columns": ["owner_id", "status"],
      "type": "index",
      "comment": "Index on owner and status for filtering"
    },
    {
      "name": "idx_team_verification",
      "columns": ["is_verified", "verified_at"],
      "type": "index",
      "comment": "Index on verification status and time"
    },
    {
      "name": "idx_team_code_type",
      "columns": ["team_code_type", "team_code"],
      "type": "index",
      "comment": "Index on team code type and code"
    },
    {
      "name": "idx_team_location",
      "columns": ["country", "state_province", "city"],
      "type": "index",
      "comment": "Index on country, state/province and city for geographic queries"
    },
    {
      "name": "idx_team_region_type",
      "columns": ["region", "type"],
      "type": "index",
      "comment": "Index on geographic region and team type"
    },
    {
      "name": "idx_team_postal_zoneinfo",
      "columns": ["postal_code", "zoneinfo"],
      "type": "index",
      "comment": "Index on postal code and zoneinfo for location services"
    },
    {
      "name": "idx_team_type_status",
      "columns": ["type_id", "status"],
      "type": "index",
      "comment": "Index on team type and status for limits and permissions"
    },
    {
      "name": "idx_team_role_type",
      "columns": ["role_id", "type_id"],
      "type": "index",
      "comment": "Index on team owner role and type for permission queries"
    }
  ],
  "relations": {
    "owner": {
      "type": "hasOne",
      "model": "__yao.user",
      "key": "owner_id",
      "foreign": "user_id"
    },
    "role": {
      "type": "hasOne",
      "model": "__yao.role",
      "key": "role_id",
      "foreign": "role_id"
    },
    "user_type": {
      "type": "hasOne",
      "model": "__yao.user.type",
      "key": "type_id",
      "foreign": "type_id"
    },
    "members": {
      "type": "hasMany",
      "model": "__yao.member",
      "key": "team_id",
      "foreign": "team_id"
    },
    "users": {
      "type": "hasManyThrough",
      "model": "__yao.user",
      "through": "__yao.member",
      "key": "team_id",
      "foreign": "team_id",
      "throughKey": "user_id",
      "throughForeign": "user_id"
    }
  },
  "values": [],
  "option": { "timestamps": true, "soft_deletes": true, "permission": true }
}
