syntax = "proto3";

package com.wix.ecom.tax.api;

import "wix/api/annotations.proto";
import "wix/api/validations.proto";
import "wix/api/errors.proto";
import "google/protobuf/wrappers.proto";
import "com/wix/ecommerce/platform_common/api/price.proto";

message ItemTaxFullDetails {
    // Taxable amount of this line item.
    com.wix.ecommerce.platform_common.api.Price taxable_amount = 1;
    // ID of the item's tax group, if specified.
    google.protobuf.StringValue tax_group_id = 2 [(.wix.api.field_exposure) = PRIVATE, (.wix.api.format) = GUID];
    // Tax rate percentage, as a decimal numeral between 0 and 1. For example, `"0.13"`.
    string tax_rate = 3 [(.wix.api.decimalValue) = { gte: "0" maxScale: 6 }];

    // The calculated tax, based on the `taxableAmount` and `taxRate`.
    com.wix.ecommerce.platform_common.api.Price total_tax = 6;

    //if breakdown exists, then the sum of rates in breakdown must equal the tax_rate here.
    //repeated TaxRateBreakdown rate_breakdown = 5 [(.wix.api.readOnly) = true];
}

message TaxRateBreakdown {
    // The name of the tax against which the calculation was performed
    string name = 1 [(.wix.api.maxLength) = 100];
    // The rate at which this tax detail was calculated
    string rate = 2 [(.wix.api.decimalValue) = {gte: "0" maxScale: 6}];
    // The amount of tax for this tax detail
    com.wix.ecommerce.platform_common.api.Price tax = 3;
}

message TaxSummary {
    //the amount on which tax is calculated, added from line items
    //com.wix.ecommerce.platform_common.api.Price taxable_amount = 1 [(.wix.api.readOnly) = true];

    // Total tax.
    com.wix.ecommerce.platform_common.api.Price total_tax = 5 [(.wix.api.readOnly) = true];

    //manual tax rate
    google.protobuf.StringValue manual_tax_rate = 3 [(.wix.api.decimalValue) = { gte: "0" maxScale: 6 }, (.wix.api.readOnly) = true, (.wix.api.field_exposure) = PRIVATE];
    // the calculator that was active when the order was created
    //    TaxCalculationDetails calculation_details = 4;
}

message TaxCalculationDetails {
    // Rate calculation type.
    RateType rate_type = 1;
    oneof CalculationDetails {
        // Reason the manual calculation was used.
        ManualCalculationReason manual_rate_reason = 2;
        // Details of the fallback rate calculation.
        AutoTaxFallbackCalculationDetails auto_tax_fallback_details = 4;
    }
}

message AutoTaxFallbackCalculationDetails {
    enum FallbackReason {
        //auto-tax failed to be calculated
        AUTO_TAX_FAILED = 0;
        //auto-tax was temporarily deactivated on a system-level
        AUTO_TAX_DEACTIVATED = 1;
    }
    //reason for fallback
    FallbackReason fallback_reason = 2;
    //invalid request (i.e. address), timeout, internal error, license error, and others will be encoded here
    .wix.api.ApplicationError error = 3;
}
enum ManualCalculationReason {
    //user set calculator in Business Manager to be Manual
    GLOBAL_SETTING_TO_MANUAL = 0;
    //specific region is on manual even though Global setting is Auto-tax
    REGION_SETTING_TO_MANUAL = 1;
}
enum RateType {
    //no tax being collected for this request due to location of purchase
    NO_TAX_COLLECTED = 0;
    //manual rate used for calculation
    MANUAL_RATE = 1;
    //autotax rate used for calculation
    AUTO_RATE = 2;
    //fallback rate used for calculation
    FALLBACK_RATE = 3;
}
