import 'package:test/test.dart';
import 'package:heartinz_essentials/heartinz_essentials.dart';

void main() {
  group('gst calulcation test', () {
    //frist test
    test('Should  calculate in base with decimal values', () {
      // Arrange
      final essentials = Essentials();

      // Act
      final GSTResult result = essentials.gstCalculate(
        mrp: essentials.toSubunit(0.234, "INR"),
        salePrice: essentials.toSubunit(0.123, "INR"),
        basePrice: essentials.toSubunit(0.1, "INR"),
        taxPercent: 18,
        quantity: 1000,
        lock: "BASEPRICE",
      );

      // Assert
      expect(result.toJson(), {
        'mrp': 23,
        'discount': 11,
        'salePrice': 12,
        'basePrice': 10,
        'gstPercent': '18',
        'taxPercentage': 18,
        'gstAmount': 2,
        'taxAmount': 2,
        'sgstPercent': '9',
        'sgstAmount': 1,
        'cgstPercent': '9',
        'cgstAmount': 1,
        'igstPercent': '18',
        'igstAmount': 2,
        'quantity': 1000,
        'lineTotalMrp': 23000,
        'lineTotalSalePrice': 11800,
        'lineTotalDiscount': 11200,
        'lineTotalBasePrice': 10000,
        'lineTotalTaxAmount': 1800,
        'lineTotalSgstAmount': 900,
        'lineTotalCgstAmount': 900,
        'lineTotalIgstAmount': 1800,
        'lineGrandTotal': 11800
      });
    });

    //second test
    test('Should work with 1', () async {
      // Arrange
      final essentials = Essentials();

      // Act
      final GSTResult result = essentials.gstCalculate(
        mrp: essentials.toSubunit(1, "INR"),
        salePrice: essentials.toSubunit(1, "INR"),
        basePrice: essentials.toSubunit(1, "INR"),
        taxPercent: 1,
        quantity: 1,
        lock: "BASEPRICE",
      );

      // Assert
      expect(result.toJson(), {
        "mrp": 101,
        "discount": 0,
        "salePrice": 101,
        "basePrice": 100,
        "gstPercent": '1',
        "taxPercentage": 1,
        "gstAmount": 1,
        "taxAmount": 1,
        "sgstPercent": '0.5',
        "sgstAmount": 0,
        "cgstPercent": '0.5',
        "cgstAmount": 0,
        "igstPercent": '1',
        "igstAmount": 1,
        "quantity": 1,
        "lineTotalMrp": 101,
        "lineTotalSalePrice": 101,
        "lineTotalDiscount": 0,
        "lineTotalBasePrice": 100,
        "lineTotalTaxAmount": 1,
        "lineTotalSgstAmount": 0,
        "lineTotalCgstAmount": 0,
        "lineTotalIgstAmount": 1,
        "lineGrandTotal": 101
      });
    });

    //third test
    test('Should calculate large decimal values', () {
      // Arrange
      final essentials = Essentials();

      // Act
      final GSTResult result = essentials.gstCalculate(
        mrp: essentials.toSubunit(1.43, "INR"),
        salePrice: essentials.toSubunit(3.53, "INR"),
        basePrice: essentials.toSubunit(3.6, "INR"),
        taxPercent: 1,
        quantity: 1,
        lock: "BASEPRICE",
      );

      // Assert
      expect(
        result.toJson(),
        {
          "mrp": 364,
          "discount": 0,
          "salePrice": 364,
          "basePrice": 360,
          "gstPercent": '1',
          "taxPercentage": 1,
          "gstAmount": 4,
          "taxAmount": 4,
          "sgstPercent": '0.5',
          "sgstAmount": 2,
          "cgstPercent": '0.5',
          "cgstAmount": 2,
          "igstPercent": '1',
          "igstAmount": 4,
          "quantity": 1,
          "lineTotalMrp": 364,
          "lineTotalSalePrice": 364,
          "lineTotalDiscount": 0,
          "lineTotalBasePrice": 360,
          "lineTotalTaxAmount": 4,
          "lineTotalSgstAmount": 2,
          "lineTotalCgstAmount": 2,
          "lineTotalIgstAmount": 4,
          "lineGrandTotal": 364
        },
      );
    });

    test('Should 1000', () {
      // Arrange
      final essentials = Essentials();

      // Act
      final GSTResult result = essentials.gstCalculate(
        mrp: essentials.toSubunit(1000.000, "INR"),
        salePrice: essentials.toSubunit(1000.000, "INR"),
        basePrice: essentials.toSubunit(1000.000, "INR"),
        taxPercent: 1,
        quantity: 1000,
        lock: "SALEPRICE",
      );

      // Assert
      expect(
        result.toJson(),
        {
          "mrp": 100000,
          "discount": 0,
          "salePrice": 100000,
          "basePrice": 99010,
          "gstPercent": '1',
          "taxPercentage": 1,
          "gstAmount": 990,
          "taxAmount": 990,
          "sgstPercent": '0.5',
          "sgstAmount": 495,
          "cgstPercent": '0.5',
          "cgstAmount": 495,
          "igstPercent": '1',
          "igstAmount": 990,
          "quantity": 1000,
          "lineTotalMrp": 100000000,
          "lineTotalSalePrice": 100000000,
          "lineTotalDiscount": 0,
          "lineTotalBasePrice": 99009901,
          "lineTotalTaxAmount": 990099,
          "lineTotalSgstAmount": 495049,
          "lineTotalCgstAmount": 495049,
          "lineTotalIgstAmount": 990099,
          "lineGrandTotal": 100000000
        },
      );
    });

    test('Should work in sale with small decimal values', () {
      // Arrange
      final essentials = Essentials();

      // Act
      final GSTResult result = essentials.gstCalculate(
        mrp: essentials.toSubunit(0.1, "INR"),
        salePrice: essentials.toSubunit(0.235, "INR"),
        basePrice: essentials.toSubunit(0.23, "INR"),
        taxPercent: 18,
        quantity: 1000,
        lock: "SALEPRICE",
      );

      // Assert
      expect(result.toJson(), {
        "mrp": 24,
        "discount": 0,
        "salePrice": 24,
        "basePrice": 20,
        "gstPercent": '18',
        "taxPercentage": 18,
        "gstAmount": 4,
        "taxAmount": 4,
        "sgstPercent": '9',
        "sgstAmount": 2,
        "cgstPercent": '9',
        "cgstAmount": 2,
        "igstPercent": '18',
        "igstAmount": 4,
        "quantity": 1000,
        "lineTotalMrp": 24000,
        "lineTotalSalePrice": 24000,
        "lineTotalDiscount": 0,
        "lineTotalBasePrice": 20339,
        "lineTotalTaxAmount": 3661,
        "lineTotalSgstAmount": 1830,
        "lineTotalCgstAmount": 1830,
        "lineTotalIgstAmount": 3661,
        "lineGrandTotal": 24000
      });
    });

    test('Should work with sale random values', () {
      // Arrange
      final essentials = Essentials();

      // Act
      final GSTResult result = essentials.gstCalculate(
        mrp: essentials.toSubunit(3.534342, "INR"),
        salePrice: essentials.toSubunit(4234234, "INR"),
        basePrice: essentials.toSubunit(534534, "INR"),
        taxPercent: 43242,
        quantity: 43242243,
        lock: "SALEPRICE",
      );

      // Assert
      expect(
        result.toJson(),
        {
          "mrp": 423423400,
          "discount": 0,
          "salePrice": 423423400,
          "basePrice": 976936,
          "gstPercent": '43242',
          "taxPercentage": 43242,
          "gstAmount": 422446464,
          "taxAmount": 422446464,
          "sgstPercent": '21621',
          "sgstAmount": 211223232,
          "cgstPercent": '21621',
          "cgstAmount": 211223232,
          "igstPercent": '43242',
          "igstAmount": 422446464,
          "quantity": 43242243.0,
          "lineTotalMrp": 18309777554686200,
          "lineTotalSalePrice": 18309777554686200,
          "lineTotalDiscount": 0,
          "lineTotalBasePrice": 42244883841738,
          "lineTotalTaxAmount": 18267532670844462,
          "lineTotalSgstAmount": 9133766335422231,
          "lineTotalCgstAmount": 9133766335422231,
          "lineTotalIgstAmount": 18267532670844462,
          "lineGrandTotal": 18309777554686200
        },
      );
    });

    //
  });
}
