-- finops.azure_sponsorship_focus_silver definition
CREATE TABLE
  `azure_sponsorship_focus_silver` (
    `RowId` char(64) NOT NULL,
    -- Date de collecte/reporting héritée du Bronze.
    -- Elle pilote les traitements incrémentaux et permet de prendre en
    -- compte les late arrivals.
    business_date DATE NOT NULL,
    `AllocatedMethodDetails` longtext DEFAULT NULL,
    `AllocatedMethodId` varchar(255) DEFAULT NULL,
    `AllocatedResourceId` text DEFAULT NULL,
    `AllocatedResourceName` text DEFAULT NULL,
    `AllocatedTags` longtext DEFAULT NULL,
    `AvailabilityZone` varchar(100) DEFAULT NULL,
    `BilledCost` decimal(38, 12) DEFAULT NULL,
    `BillingAccountId` varchar(255) NOT NULL,
    `BillingAccountName` text DEFAULT NULL,
    `BillingAccountType` varchar(100) NOT NULL,
    `BillingCurrency` char(3) NOT NULL,
    `BillingPeriodStart` datetime(6) NOT NULL,
    `BillingPeriodEnd` datetime(6) NOT NULL,
    `CapacityReservationId` varchar(255) DEFAULT NULL,
    `CapacityReservationStatus` varchar(100) DEFAULT NULL,
    `ChargeCategory` varchar(100) NOT NULL,
    `ChargeClass` varchar(100) DEFAULT NULL,
    `ChargeDescription` text DEFAULT NULL,
    `ChargeFrequency` varchar(100) NOT NULL,
    `ChargePeriodStart` datetime(6) NOT NULL,
    `ChargePeriodEnd` datetime(6) NOT NULL,
    `CommitmentDiscountCategory` varchar(100) DEFAULT NULL,
    `CommitmentDiscountId` varchar(255) DEFAULT NULL,
    `CommitmentDiscountName` text DEFAULT NULL,
    `CommitmentDiscountQuantity` decimal(38, 12) DEFAULT NULL,
    `CommitmentDiscountStatus` varchar(100) DEFAULT NULL,
    `CommitmentDiscountType` varchar(100) DEFAULT NULL,
    `CommitmentDiscountUnit` varchar(255) DEFAULT NULL,
    `CommitmentProgramEligibilityDetails` longtext DEFAULT NULL,
    `ConsumedQuantity` decimal(38, 12) NOT NULL,
    `ConsumedUnit` varchar(255) DEFAULT NULL,
    `ContractApplied` varchar(255) DEFAULT NULL,
    `ContractedCost` decimal(38, 12) DEFAULT NULL,
    `ContractedUnitPrice` decimal(38, 12) DEFAULT NULL,
    `EffectiveCost` decimal(38, 12) DEFAULT NULL,
    `HostProviderName` varchar(255) DEFAULT NULL,
    `InvoiceDetailId` varchar(255) DEFAULT NULL,
    `InvoiceId` varchar(255) DEFAULT NULL,
    `InvoiceIssuerName` varchar(255) DEFAULT NULL,
    `ListCost` decimal(38, 12) DEFAULT NULL,
    `ListUnitPrice` decimal(38, 12) DEFAULT NULL,
    `PricingCategory` varchar(100) DEFAULT NULL,
    `PricingCurrency` char(3) DEFAULT NULL,
    `PricingCurrencyContractedUnitPrice` decimal(38, 12) DEFAULT NULL,
    `PricingCurrencyEffectiveCost` decimal(38, 12) DEFAULT NULL,
    `PricingCurrencyListUnitPrice` decimal(38, 12) DEFAULT NULL,
    `PricingQuantity` decimal(38, 12) DEFAULT NULL,
    `PricingUnit` varchar(255) DEFAULT NULL,
    `RegionId` varchar(255) DEFAULT NULL,
    `RegionName` varchar(255) DEFAULT NULL,
    `ResourceId` text DEFAULT NULL,
    `ResourceName` text DEFAULT NULL,
    `ResourceType` text DEFAULT NULL,
    `ServiceProviderName` varchar(255) DEFAULT NULL,
    `ServiceCategory` varchar(255) DEFAULT NULL,
    `ServiceName` text DEFAULT NULL,
    `ServiceSubcategory` text DEFAULT NULL,
    `SkuId` varchar(255) DEFAULT NULL,
    `SkuMeter` text DEFAULT NULL,
    `SkuPriceDetails` longtext DEFAULT NULL,
    `SkuPriceId` varchar(255) DEFAULT NULL,
    `SubAccountId` varchar(255) NOT NULL,
    `SubAccountName` text DEFAULT NULL,
    `SubAccountType` varchar(100) DEFAULT NULL,
    `Tags` longtext DEFAULT NULL,
    `x_Provider` varchar(50) NOT NULL,
    `x_BillingModel` varchar(100) NOT NULL,
    `x_BilledCostBasis` varchar(255) NOT NULL,
    `x_FocusComplianceStatus` varchar(100) NOT NULL,
    `x_ResourceGroupName` varchar(255) DEFAULT NULL,
    `x_UsageMeterId` varchar(128) DEFAULT NULL,
    `x_UsageMeterName` text DEFAULT NULL,
    `x_UsageMeterCategory` varchar(500) DEFAULT NULL,
    `x_UsageMeterSubCategory` varchar(500) DEFAULT NULL,
    `x_UsageMeterRegion` varchar(255) DEFAULT NULL,
    `x_SkuMeterId` varchar(128) NOT NULL,
    `x_SkuPriceMeterId` varchar(128) DEFAULT NULL,
    `x_SkuRegion` varchar(255) DEFAULT NULL,
    `x_PricingSource` varchar(100) DEFAULT NULL,
    `x_PricingConfidence` varchar(100) DEFAULT NULL,
    `x_PricingMatchMethod` varchar(150) NOT NULL,
    `x_PricingMatchCandidateCount` int(11) NOT NULL DEFAULT 0,
    `x_PricingUnitDescription` varchar(255) DEFAULT NULL,
    `x_PricingBlockSize` decimal(38, 12) DEFAULT NULL,
    `x_PricingQuantityStatus` varchar(100) DEFAULT NULL,
    `x_RatingReconciliationStatus` varchar(100) DEFAULT NULL,
    `x_EstimatedPricingUnitPrice` decimal(38, 12) DEFAULT NULL,
    `x_EstimatedCost` decimal(38, 12) DEFAULT NULL,
    `x_PriceSheetBillingCurrency` char(3) DEFAULT NULL,
    `x_PriceSheetSnapshot` date DEFAULT NULL,
    `x_SourcePriceId` text DEFAULT NULL,
    `x_RateCardOfferDurableId` varchar(128) DEFAULT NULL,
    `x_RateCardCurrency` char(3) DEFAULT NULL,
    `x_RateCardLocale` varchar(32) DEFAULT NULL,
    `x_RateCardRegionInfo` varchar(64) DEFAULT NULL,
    `x_RateCardEffectiveDate` datetime(6) DEFAULT NULL,
    `x_RateCardMeterId` varchar(128) DEFAULT NULL,
    `x_RateCardMeterName` text DEFAULT NULL,
    `x_RateCardMeterCategory` varchar(500) DEFAULT NULL,
    `x_RateCardMeterSubCategory` varchar(500) DEFAULT NULL,
    `x_RateCardMeterRegion` varchar(255) DEFAULT NULL,
    `x_RateCardUnit` varchar(255) DEFAULT NULL,
    `x_RateCardUnitPrice` decimal(38, 12) DEFAULT NULL,
    `x_RateCardIncludedQuantity` decimal(38, 12) DEFAULT NULL,
    `x_RateCardMeterRatesJson` longtext DEFAULT NULL,
    `x_RateCardSourceHash` char(64) DEFAULT NULL,
    `x_RateCardFirstSeenAt` datetime(6) DEFAULT NULL,
    `x_RateCardLastSeenAt` datetime(6) DEFAULT NULL,
    `x_RateCardSourceBronzeId` bigint(20) unsigned DEFAULT NULL,
    `x_RateCardSourceIngestionRunId` char(36) DEFAULT NULL,
    `x_RateCardIngestionRunId` char(36) DEFAULT NULL,
    `x_RateCardNormalizationRunId` char(36) DEFAULT NULL,
    `x_RateCardNormalizationVersion` varchar(64) DEFAULT NULL,
    `x_RateCardNormalizedAt` datetime(6) DEFAULT NULL,
    `x_RetailPriceKey` char(64) DEFAULT NULL,
    `x_RetailPricingHash` char(64) DEFAULT NULL,
    `x_RetailCurrency` char(3) DEFAULT NULL,
    `x_RetailMeterId` varchar(128) DEFAULT NULL,
    `x_RetailMeterName` text DEFAULT NULL,
    `x_RetailEffectiveStartDate` datetime(6) DEFAULT NULL,
    `x_RetailArmRegionName` varchar(255) DEFAULT NULL,
    `x_RetailLocation` varchar(500) DEFAULT NULL,
    `x_RetailUnitOfMeasure` varchar(255) DEFAULT NULL,
    `x_RetailReservationTerm` varchar(64) DEFAULT NULL,
    `x_RetailPrice` decimal(38, 12) DEFAULT NULL,
    `x_RetailUnitPrice` decimal(38, 12) DEFAULT NULL,
    `x_RetailTierMinimumUnits` decimal(38, 12) DEFAULT NULL,
    `x_RetailProductId` varchar(255) DEFAULT NULL,
    `x_RetailProductName` text DEFAULT NULL,
    `x_RetailSkuId` varchar(255) DEFAULT NULL,
    `x_RetailSkuName` text DEFAULT NULL,
    `x_RetailServiceId` varchar(255) DEFAULT NULL,
    `x_RetailServiceName` varchar(500) DEFAULT NULL,
    `x_RetailServiceFamily` varchar(500) DEFAULT NULL,
    `x_RetailApiType` varchar(100) DEFAULT NULL,
    `x_RetailArmSkuName` varchar(500) DEFAULT NULL,
    `x_RetailIsPrimaryMeterRegion` tinyint(1) DEFAULT NULL,
    `x_RetailSourceHash` char(64) DEFAULT NULL,
    `x_RetailFirstSeenAt` datetime(6) DEFAULT NULL,
    `x_RetailLastSeenAt` datetime(6) DEFAULT NULL,
    `x_RetailMatchMethod` varchar(150) DEFAULT NULL,
    `x_RetailCandidateCount` int(11) NOT NULL DEFAULT 0,
    `x_RetailSourceBronzeId` bigint(20) unsigned DEFAULT NULL,
    `x_RetailSourceIngestionRunId` char(36) DEFAULT NULL,
    `x_RetailIngestionRunId` char(36) DEFAULT NULL,
    `x_RetailNormalizationRunId` char(36) DEFAULT NULL,
    `x_RetailNormalizationVersion` varchar(64) DEFAULT NULL,
    `x_RetailNormalizedAt` datetime(6) DEFAULT NULL,
    `x_SourceUsageId` text DEFAULT NULL,
    `x_SourceUsageRowId` bigint(20) unsigned DEFAULT NULL,
    `x_SourceBronzeId` bigint(20) unsigned DEFAULT NULL,
    `x_SourceRecordNumber` int(11) DEFAULT NULL,
    `x_SourcePayloadHash` char(64) DEFAULT NULL,
    `x_IngestionRunId` char(36) DEFAULT NULL,
    `x_NormalizationRunId` char(36) DEFAULT NULL,
    `x_NormalizationVersion` varchar(64) DEFAULT NULL,
    `x_NormalizedAt` datetime(6) DEFAULT NULL,
    `x_GeneratedAt` datetime(6) NOT NULL,
    `created_at` datetime(6) NOT NULL DEFAULT current_timestamp(6),
    PRIMARY KEY (`RowId`),
    KEY idx_sponsorship_focus_business_date (business_date),
    KEY `idx_sponsorship_focus_charge_period` (`ChargePeriodStart`, `ChargePeriodEnd`),
    KEY `idx_sponsorship_focus_billing_period` (`BillingPeriodStart`, `BillingPeriodEnd`),
    KEY `idx_sponsorship_focus_subscription_date` (`SubAccountId`, `ChargePeriodStart`),
    KEY `idx_sponsorship_focus_meter_date` (`x_SkuMeterId`, `ChargePeriodStart`),
    KEY `idx_sponsorship_focus_pricing_source` (`x_PricingSource`, `ChargePeriodStart`),
    KEY `idx_sponsorship_focus_rate_card_version` (
      `x_RateCardOfferDurableId`,
      `x_RateCardCurrency`,
      `x_SkuMeterId`,
      `x_RateCardEffectiveDate`
    ),
    KEY `idx_sponsorship_focus_retail_version` (
      `x_RetailCurrency`,
      `x_RetailMeterId`,
      `x_RetailEffectiveStartDate`
    ),
    KEY `idx_sponsorship_focus_source_usage_row` (`x_SourceUsageRowId`),
    KEY `idx_sponsorship_focus_source_bronze` (`x_SourceBronzeId`),
    KEY `idx_sponsorship_focus_ingestion_run` (`x_IngestionRunId`),
    KEY `idx_sponsorship_focus_normalization_run` (`x_NormalizationRunId`),
    KEY `idx_sponsorship_focus_resource_id` (`ResourceId`(255)),
    KEY `idx_sponsorship_focus_generated` (`x_GeneratedAt`),
    KEY `idx_sponsorship_focus_usage_meter_date` (`x_UsageMeterId`, `ChargePeriodStart`),
    KEY `idx_sponsorship_focus_usage_category_date` (`x_UsageMeterCategory`, `ChargePeriodStart`),
    KEY `idx_sponsorship_focus_created_at` (`created_at`),
    CONSTRAINT ck_focus_tags_json CHECK (
      Tags IS NULL
      OR JSON_VALID(Tags)
    ),
    CONSTRAINT `ck_focus_sku_price_details_json` CHECK (
      `SkuPriceDetails` is null
      or json_valid(`SkuPriceDetails`)
    ),
    CONSTRAINT `ck_focus_rate_card_meter_rates_json` CHECK (
      `x_RateCardMeterRatesJson` is null
      or json_valid(`x_RateCardMeterRatesJson`)
    ),
    CONSTRAINT `ck_focus_allocated_method_details_json` CHECK (
      `AllocatedMethodDetails` is null
      or json_valid(`AllocatedMethodDetails`)
    ),
    CONSTRAINT `ck_focus_allocated_tags_json` CHECK (
      `AllocatedTags` is null
      or json_valid(`AllocatedTags`)
    ),
    CONSTRAINT `ck_focus_commitment_eligibility_json` CHECK (
      `CommitmentProgramEligibilityDetails` is null
      or json_valid(`CommitmentProgramEligibilityDetails`)
    )
  ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci;