from alpaca_trade_api.entity import Asset, BarSet


def list_assets(tradeapi):
    tradeapi.REST().list_assets.return_value = [
        Asset({'asset_class': 'us_equity',
               'exchange': 'NYSE',
               'id': '3ca0202f-01f4-41a0-bb0c-c8864e767ebd',
               'status': 'active',
               'symbol': 'AA',
               'tradable': True}),
        Asset({'asset_class': 'us_equity',
               'exchange': 'NYSE',
               'id': '7595a8d2-68a6-46d7-910c-6b1958491f5c',
               'status': 'active',
               'symbol': 'A',
               'tradable': True}),
    ]


def get_barset(tradeapi):
    tradeapi.REST().get_barset.return_value = BarSet({
        "AA": [{"t": 1544129220,
                "o": 172.26,
                "h": 172.3,
                "l": 172.16,
                "c": 172.18,
                "v": 3892}]})


def list_financials(tradeapi):
    tradeapi.REST().polygon.get.return_value = {
        'AA': [{'symbol': 'AA',
                'reportDate': '2018-06-30T00:00:00.000Z',
                'reportDateStr': '2018-06-30',
                'grossProfit': 947000000,
                'costOfRevenue': 2632000000,
                'operatingRevenue': 3579000000,
                'totalRevenue': 3579000000,
                'operatingIncome': 682000000,
                'netIncome': 75000000,
                'researchAndDevelopment': 9000000,
                'operatingExpense': 265000000,
                'currentAssets': 4281000000,
                'totalAssets': 16518000000,
                'totalLiabilities': None,
                'currentCash': 1095000000,
                'currentDebt': 13000000,
                'totalCash': 1089000000,
                'totalDebt': 1929000000,
                'shareholderEquity': 5024000000,
                'cashChange': -97000000,
                'cashFlow': -430000000,
                'operatingGainsLosses': 38000000},
               {'symbol': 'AA',
                'reportDate': '2018-03-31T00:00:00.000Z',
                'reportDateStr': '2018-03-31',
                'grossProfit': 709000000,
                'costOfRevenue': 2381000000,
                'operatingRevenue': 3090000000,
                'totalRevenue': 3090000000,
                'operatingIncome': 440000000,
                'netIncome': 150000000,
                'researchAndDevelopment': 8000000,
                'operatingExpense': 269000000,
                'currentAssets': 4149000000,
                'totalAssets': 17096000000,
                'totalLiabilities': None,
                'currentCash': 1203000000,
                'currentDebt': 15000000,
                'totalCash': 1196000000,
                'totalDebt': 1460000000,
                'shareholderEquity': 5368000000,
                'cashChange': -166000000,
                'cashFlow': 55000000,
                'operatingGainsLosses': 29000000},
               {'symbol': 'AA',
                'reportDate': '2017-12-31T00:00:00.000Z',
                'reportDateStr': '2017-12-31',
                'grossProfit': 815000000,
                'costOfRevenue': 2359000000,
                'operatingRevenue': 3174000000,
                'totalRevenue': 3174000000,
                'operatingIncome': 531000000,
                'netIncome': -196000000,
                'researchAndDevelopment': 9000000,
                'operatingExpense': 284000000,
                'currentAssets': 4238000000,
                'totalAssets': 17447000000,
                'totalLiabilities': 12924000000,
                'currentCash': 1358000000,
                'currentDebt': 16000000,
                'totalCash': 1358000000,
                'totalDebt': 1404000000,
                'shareholderEquity': 4523000000,
                'cashChange': 232000000,
                'cashFlow': 455000000,
                'operatingGainsLosses': 35000000},
               {'symbol': 'AA',
                'reportDate': '2017-09-30T00:00:00.000Z',
                'reportDateStr': '2017-09-30',
                'grossProfit': 603000000,
                'costOfRevenue': 2361000000,
                'operatingRevenue': 2964000000,
                'totalRevenue': 2964000000,
                'operatingIncome': 331000000,
                'netIncome': 113000000,
                'researchAndDevelopment': 8000000,
                'operatingExpense': 272000000,
                'currentAssets': 3804000000,
                'totalAssets': 17254000000,
                'totalLiabilities': 11392000000,
                'currentCash': 1119000000,
                'currentDebt': 17000000,
                'totalCash': 1119000000,
                'totalDebt': 1401000000,
                'shareholderEquity': 5862000000,
                'cashChange': 175000000,
                'cashFlow': 384000000,
                'operatingGainsLosses': 16000000},
               {'symbol': 'AA',
                'reportDate': '2017-06-30T00:00:00.000Z',
                'reportDateStr': '2017-06-30',
                'grossProfit': 550000000,
                'costOfRevenue': 2309000000,
                'operatingRevenue': 2859000000,
                'totalRevenue': 2859000000,
                'operatingIncome': 280000000,
                'netIncome': 75000000,
                'researchAndDevelopment': 8000000,
                'operatingExpense': 270000000,
                'currentAssets': 3583000000,
                'totalAssets': 16929000000,
                'totalLiabilities': 10975000000,
                'currentCash': 954000000,
                'currentDebt': 19000000,
                'totalCash': 954000000,
                'totalDebt': 1437000000,
                'shareholderEquity': 5954000000,
                'cashChange': 146000000,
                'cashFlow': 311000000,
                'operatingGainsLosses': 46000000}]}


def list_companies(tradeapi):
    tradeapi.REST().polygon.get.return_value = [{
        '_id': '5a77fa81333c4e001174b897',
        'listdate': '1999-11-18',
        'cik': '0001090872',
        'bloomberg': 'EQ0087231700001000',
        'figi': None,
        'lei': 'QUIX8Y7A2WP0XRMW7G29',
        'sic': 3826,
        'country': 'us',
        'industry': 'Medical Diagnostics & Research',
        'sector': 'Healthcare',
        'marketcap': 20626540000,
        'employees': 131,
        'phone': '(408) 345-8886',
        'ceo': 'Michael R. McMullen',
        'url': 'http://www.agilent.com',
        'description': "Agilent Technologies, Inc. provides application focused solutions to the life sciences, diagnostics, and applied chemical markets worldwide. Its Life Sciences and Applied Markets segment offers liquid chromatography systems and components; liquid chromatography mass spectrometry systems; gas chromatography systems and components; gas chromatography mass spectrometry systems; inductively coupled plasma mass spectrometry instruments; atomic absorption instruments; microwave plasma-atomic emission spectrometry instruments; inductively coupled plasma optical emission spectrometry instruments; laboratory software and informatics systems; laboratory automation and robotic systems; dissolution testing; vacuum pumps; and measurement technologies. The company's Diagnostics and Genomics segment provides reagents, instruments, software, and consumables; arrays for DNA mutation detection, genotyping, gene copy number determination, identification of gene rearrangements, DNA methylation profiling, and gene expression profiling, as well as sequencing target enrichment services; and equipment focused on production of synthesized oligonucleotides for use as active pharmaceutical ingredients. Its Agilent CrossLab segment offers GC and LC columns, sample preparation products, custom chemistries, and various laboratory instrument supplies; and startup, operational, training, and compliance support, as well as asset management and consultation services. The company markets and sells its products through direct sales, electronic commerce, resellers, manufacturers' representatives, and distributors. It has a collaboration agreement with University of Leuven to focus on detecting genetic abnormalities in cell-free DNA and embryo biopsies. Agilent Technologies, Inc. was founded in 1999 and is headquartered in Santa Clara, California.",  # noqa
        'exchange': 'New York Stock Exchange',
        'name': 'Agilent Technologies Inc',
        'symbol': 'A',
        '__v': 15,
        'logo': 'https://s3.polygon.io/logos/a/logo.png',
        'created': '2018-02-05T06:32:33.960Z',
        'updated': '2018-02-05T06:32:33.960Z',
        'tags': ['Healthcare',
                 'Diagnostics & Research',
                 'Medical Diagnostics & Research'],
        'similar': ['NATI',
                    'ILMN',
                    'BRKR',
                    'AME',
                    'DHR',
                    'GE',
                    'TER',
                    'TMO',
                    'PKI',
                    'XLV']},
        {'_id': '5a77fa83333c4e001174b898',
         'listdate': '1990-01-02',
         'cik': '0001675149',
         'bloomberg': 'EQ0000000045469815',
         'figi': None,
         'lei': 'ABPN11VOHLHX6QR7XQ48',
         'sic': 3334,
         'country': 'us',
         'industry': 'Metals & Mining',
         'sector': 'Basic Materials',
         'marketcap': 7837461871,
         'employees': 60000,
         'phone': '412-315-2900',
         'ceo': 'Roy C. Harvey',
         'url': 'http://www.alcoa.com',
         'description': 'Alcoa Corporation produces and sells bauxite, alumina, and aluminum products. It operates through six segments, Bauxite, Alumina, Aluminum, Cast Products, Energy, and Rolled Products. The company also offers aluminum cast products; and aluminum sheets for the production of cans for beverage, food, and pet food. In addition, it engages in the generation and sale of renewable energy, as well as provision of ancillary services. The company was formerly known as Alcoa Upstream Corporation and changed its name to Alcoa Corporation in October 2016. Alcoa Corporation is based in New York, New York.',  # noqa
         'exchange': 'New York Stock Exchange',
         'name': 'Alcoa Corp',
         'symbol': 'AA',
         '__v': 19,
         'logo': 'https://s3.polygon.io/logos/aa/logo.png',
         'created': '2018-02-05T06:32:35.464Z',
         'updated': '2018-02-05T06:32:35.464Z',
         'tags': ['Basic Materials', 'Aluminum', 'Metals & Mining'],
         'similar': ['BBL', 'CENX', 'KALU', 'BHP', 'ACH']}]
