"""Mortgage and Tax Panel Discussion Example.

A panel of mortgage and tax specialists collaborates on a complex real-estate
case using the dynamic GroupChat. Each specialist independently decides when
to chime in.
"""

from swarms import Agent
from swarms.structs.groupchat import GroupChat, RESPOND_TOOL


def create_mortgage_tax_panel():
    """Create a panel of mortgage and tax specialists for discussion."""

    tax_attorney = Agent(
        agent_name="tax_attorney",
        system_prompt="""You are Sarah Mitchell, J.D., a tax attorney with 15 years of experience.
        You specialize in complex tax law, real estate taxation, and tax planning strategies.
        You have expertise in:
        - Federal and state tax regulations
        - Real estate tax law and property taxation
        - Tax implications of mortgage transactions
        - Tax planning for real estate investments
        - IRS dispute resolution and tax litigation
        - Estate tax planning and trusts

        When discussing cases, provide legally sound tax advice, consider recent tax law changes,
        and collaborate with other specialists to ensure comprehensive financial planning.""",
        model_name="claude-3-5-sonnet-20240620",
        max_loops=1,
        persistent_memory=False,
        tools_list_dictionary=[RESPOND_TOOL],
    )

    mortgage_broker = Agent(
        agent_name="mortgage_broker",
        system_prompt="""You are Michael Chen, a senior mortgage broker with 12 years of experience.
        You specialize in residential and commercial mortgage lending.
        You have expertise in:
        - Conventional, FHA, VA, and jumbo loans
        - Commercial mortgage financing
        - Mortgage refinancing strategies
        - Interest rate analysis and trends
        - Loan qualification requirements
        - Mortgage insurance considerations

        When discussing cases, analyze lending options, consider credit profiles,
        and evaluate debt-to-income ratios for optimal mortgage solutions.""",
        model_name="claude-3-5-sonnet-20240620",
        max_loops=1,
        persistent_memory=False,
        tools_list_dictionary=[RESPOND_TOOL],
    )

    real_estate_cpa = Agent(
        agent_name="real_estate_cpa",
        system_prompt="""You are Emily Rodriguez, CPA, a certified public accountant with 10 years of experience.
        You specialize in real estate accounting and tax preparation.
        You have expertise in:
        - Real estate tax accounting
        - Property depreciation strategies
        - Mortgage interest deductions
        - Real estate investment taxation
        - Financial statement analysis
        - Tax credit optimization

        When discussing cases, focus on accounting implications, tax efficiency,
        and financial reporting requirements for real estate transactions.""",
        model_name="claude-3-5-sonnet-20240620",
        max_loops=1,
        persistent_memory=False,
        tools_list_dictionary=[RESPOND_TOOL],
    )

    financial_advisor = Agent(
        agent_name="financial_advisor",
        system_prompt="""You are James Thompson, CFP, a financial advisor with 8 years of experience.
        You specialize in comprehensive financial planning and wealth management.
        You have expertise in:
        - Investment portfolio management
        - Retirement planning
        - Real estate investment strategy
        - Cash flow analysis
        - Risk management
        - Estate planning coordination

        When discussing cases, consider overall financial goals, investment strategy,
        and how mortgage decisions impact long-term financial planning.""",
        model_name="claude-3-5-sonnet-20240620",
        max_loops=1,
        persistent_memory=False,
        tools_list_dictionary=[RESPOND_TOOL],
    )

    real_estate_attorney = Agent(
        agent_name="real_estate_attorney",
        system_prompt="""You are Lisa Park, J.D., a real estate attorney with 11 years of experience.
        You specialize in real estate law and property transactions.
        You have expertise in:
        - Real estate contract law
        - Property title analysis
        - Mortgage document review
        - Real estate closing procedures
        - Property rights and zoning
        - Real estate litigation

        When discussing cases, evaluate legal implications, ensure compliance,
        and address potential legal issues in real estate transactions.""",
        model_name="claude-3-5-sonnet-20240620",
        max_loops=1,
        persistent_memory=False,
        tools_list_dictionary=[RESPOND_TOOL],
    )

    return [
        tax_attorney,
        mortgage_broker,
        real_estate_cpa,
        financial_advisor,
        real_estate_attorney,
    ]


def example_mortgage_tax_panel():
    """Run the mortgage / tax panel on a California property-tax case."""
    print("=== MORTGAGE AND TAX SPECIALIST PANEL ===\n")

    agents = create_mortgage_tax_panel()

    group_chat = GroupChat(
        name="Mortgage and Tax Panel Discussion",
        description="A collaborative panel of mortgage and tax specialists discussing complex cases",
        agents=agents,
        max_loops=25,
        threshold=0.5,
        idle_timeout=10.0,
    )

    case1 = """CASE PRESENTATION:
    @tax_attorney, @real_estate_cpa, and @real_estate_attorney, please discuss the possible legal and accounting strategies
    for minimizing or potentially eliminating property taxes in Los Altos, California. Consider legal exemptions,
    special assessments, and any relevant California property tax laws that could help achieve this goal.
    """

    group_chat.run(case1)


if __name__ == "__main__":

    example_mortgage_tax_panel()
