@isTest
private class LexNewOPDButtonOpportunityTest {
    private static Id pricebookId = ControllerUtil.getStandardPricebook().Id;
    static testMethod void method() {

        Opportunity opp = new Opportunity(
            Name='Opp',
            StageName='询价',
            CloseDate=Date.today().addDays(10),
            Close_Forecasted_Date__c=Date.today(),
            CurrencyIsoCode = 'CNY'
        );
        insert opp;

        // oppLine oppline = new oppLine();
        // oppline.opp = opp;
        // oppline.quoteNum = 1;
        Id productOlympusProductsRecordTypeId = Schema.SObjectType.Product2.getRecordTypeInfosByDeveloperName().get('OlympusProducts').getRecordTypeId();
        Product2 prd1 = new Product2();
        prd1.Name = 'Prd1';
        prd1.RecordTypeId = productOlympusProductsRecordTypeId;
        prd1.ProductCode_Ext__c = 'Prd1';
        prd1.ProductCode = 'Prd1';
        prd1.Important_product__c = true;
        prd1.Asset_Model_No__c = '1001';
        prd1.Important_Rroduct_1GI__c = true;
        prd1.RentalSubject__c = true;
        prd1.Fixture_Model_No__c = '1001';
        prd1.IsActive = true;
        insert prd1;  

        Quote q = new Quote(
            Name = 'quote',
            OpportunityId = opp.Id,
            Pricebook2Id = pricebookId
        );
        insert q;
        opp.Estimation_Id__c = String.valueOf(q.Id);
        update opp;
        
        PricebookEntry entry = new PricebookEntry( Pricebook2Id = pricebookId, Product2Id = prd1.Id);
        entry.UnitPrice = 0;
        entry.IsActive = true;
        entry.UseStandardPrice = false;
        entry.CurrencyIsoCode = 'CNY';
        insert entry;

        QuoteLineItem quoteItem = new QuoteLineItem();
        quoteItem.Name__c = 'テスト商品';
        quoteItem.QuoteId = q.id;
        quoteItem.Quantity = 1;
        quoteItem.Cost_Subtotal__c = 0;
        quoteItem.Cost__c = 200;
        quoteItem.Item_Order__c  = 3;
        quoteItem.UnitPrice = 10;
        quoteItem.Product2Id = prd1.id;
        quoteItem.PricebookEntryId = entry.Id;
        quoteItem.OppIsLendMark__c = false;
        insert quoteItem;


        OPDPlan__c oPDPlan1 = new OPDPlan__c();
        oPDPlan1.Status__c = '计划中';
        oPDPlan1.OPDPlan_ImplementDate__c =  Date.today().addMonths(1);
        oPDPlan1.NoOpp_Reason__c = 'HCP对应';     //无询价理由
        oPDPlan1.OPDLendSortDraft__c = 1;       //备品借出优先度
        oPDPlan1.OPDType__c = '事件';
        oPDPlan1.Related_Opportunity1_ID__c = opp.Id;
        oPDPlan1.NoOpp_Reason__c = null;
        insert oPDPlan1;


        List<ProLine> proLines = new List<ProLine>();
        ProLine proLine1 = new ProLine();
        // proLine1.Id = planRE.Id;
        proLine1.Quantity = 10;
        proLine1.ProductName = 'CF-H170I1';
        proLine1.ProductCode= '1001';
        proLine1.ProductModel= '1001';
        // proLine1.QuoteNo = 
        proLines.add(proLine1);

        String jsonRecords = System.JSON.serialize(proLines);
        LexNewOPDButtonOpportunityController.initCancleSumbit(oPDPlan1.Id);
        LexNewOPDButtonOpportunityController.initNewOPDButton2(opp.Id);
        LexNewOPDButtonOpportunityController.initGetQuote(opp.Id);
        LexNewOPDButtonOpportunityController.createProductTags(jsonRecords,opp.Id);
        LexNewOPDButtonOpportunityController.initReportSubmit(oPDPlan1.Id);
    }

    public class ProLine {
        // @AuraEnabled
        // public Id Id { get; set; } 
        @AuraEnabled
        public Integer Quantity { get; set; } 
        @AuraEnabled
        public String ProductName { get; set; } 
        @AuraEnabled
        public String ProductCode { get; set; }  
        @AuraEnabled
        public String ProductModel { get; set; } 
        @AuraEnabled
        public String QuoteNo { get; set; } 
        @AuraEnabled
        public String FixtureModel { get; set; } 
    } 

    public class oppLine {
        @AuraEnabled
        public Opportunity opp { get; set; } 
        @AuraEnabled
        public Integer quoteNum { get; set; } 
    } 
}