"""Generate a sample Canadian shareholder agreement PDF for the PartnerLogic PoC."""

from __future__ import annotations

from pathlib import Path

from reportlab.lib.colors import HexColor
from reportlab.lib.enums import TA_CENTER, TA_JUSTIFY, TA_RIGHT
from reportlab.lib.pagesizes import letter
from reportlab.lib.styles import ParagraphStyle, getSampleStyleSheet
from reportlab.lib.units import inch
from reportlab.platypus import HRFlowable, PageBreak, Paragraph, SimpleDocTemplate, Spacer

ROOT = Path(__file__).resolve().parent.parent
OUTPUT = ROOT / "data" / "shareholder_agreement.pdf"

NAVY = HexColor("#0B0B0C")
RED = HexColor("#C8102E")
MUTED = HexColor("#4A4743")
RULE = HexColor("#C8102E")


def _styles() -> dict[str, ParagraphStyle]:
    base = getSampleStyleSheet()
    return {
        "kicker": ParagraphStyle(
            "Kicker",
            parent=base["Normal"],
            fontName="Times-Bold",
            fontSize=8,
            textColor=RED,
            alignment=TA_CENTER,
            spaceAfter=6,
        ),
        "cover_title": ParagraphStyle(
            "CoverTitle",
            parent=base["Title"],
            fontName="Times-Bold",
            fontSize=22,
            leading=26,
            textColor=NAVY,
            alignment=TA_CENTER,
            spaceAfter=8,
        ),
        "cover_sub": ParagraphStyle(
            "CoverSub",
            parent=base["Normal"],
            fontName="Times-Italic",
            fontSize=11,
            leading=14,
            textColor=MUTED,
            alignment=TA_CENTER,
            spaceAfter=6,
        ),
        "meta": ParagraphStyle(
            "Meta",
            parent=base["Normal"],
            fontName="Times-Roman",
            fontSize=10,
            leading=14,
            alignment=TA_CENTER,
            textColor=NAVY,
            spaceAfter=4,
        ),
        "h1": ParagraphStyle(
            "H1",
            parent=base["Heading1"],
            fontName="Times-Bold",
            fontSize=13,
            leading=16,
            textColor=NAVY,
            spaceBefore=16,
            spaceAfter=8,
        ),
        "h2": ParagraphStyle(
            "H2",
            parent=base["Heading2"],
            fontName="Times-Bold",
            fontSize=11,
            leading=14,
            textColor=NAVY,
            spaceBefore=12,
            spaceAfter=6,
        ),
        "body": ParagraphStyle(
            "Body",
            parent=base["Normal"],
            fontName="Times-Roman",
            fontSize=10,
            leading=14,
            alignment=TA_JUSTIFY,
            spaceAfter=8,
        ),
        "defn": ParagraphStyle(
            "Defn",
            parent=base["Normal"],
            fontName="Times-Roman",
            fontSize=10,
            leading=14,
            alignment=TA_JUSTIFY,
            leftIndent=12,
            spaceAfter=6,
        ),
        "footer": ParagraphStyle(
            "Footer",
            parent=base["Normal"],
            fontName="Times-Italic",
            fontSize=8,
            textColor=MUTED,
            alignment=TA_RIGHT,
        ),
        "center": ParagraphStyle(
            "Center",
            parent=base["Normal"],
            fontName="Times-Roman",
            fontSize=10,
            leading=14,
            alignment=TA_CENTER,
            spaceAfter=6,
        ),
    }


def _header_footer(canvas, doc) -> None:
    canvas.saveState()
    canvas.setFillColor(RED)
    canvas.rect(0, letter[1] - 6, letter[0], 6, fill=1, stroke=0)
    canvas.setFillColor(MUTED)
    canvas.setFont("Times-Italic", 8)
    canvas.drawString(0.85 * inch, 0.5 * inch, "PRIVILEGED AND CONFIDENTIAL — MLT AIKINS WORK PRODUCT")
    canvas.drawRightString(letter[0] - 0.85 * inch, 0.5 * inch, f"Page {doc.page}")
    canvas.restoreState()


def _p(styles, key: str, text: str):
    return Paragraph(text, styles[key])


def build_story(styles: dict[str, ParagraphStyle]) -> list:
    s = styles
    story: list = []

    story += [
        Spacer(1, 1.3 * inch),
        _p(s, "kicker", "UNANIMOUS SHAREHOLDER AGREEMENT"),
        HRFlowable(width="40%", thickness=1, color=RULE, spaceBefore=4, spaceAfter=14, hAlign="CENTER"),
        _p(s, "cover_title", "UNANIMOUS SHAREHOLDER AGREEMENT"),
        _p(s, "cover_sub", "Prairie Harvest Holdings Inc."),
        Spacer(1, 0.25 * inch),
        _p(s, "meta", "Effective as of 1 September 2024"),
        _p(s, "meta", "Governing Law: Province of Saskatchewan"),
        Spacer(1, 0.5 * inch),
        _p(
            s,
            "center",
            "Among Prairie Harvest Holdings Inc. (the &quot;Corporation&quot;), "
            "Elkhorn Capital Partners Ltd. (&quot;Elkhorn&quot;), "
            "Northern Grain Ventures Inc. (&quot;Northern&quot;), "
            "and Mara Chen (the &quot;Founder&quot;).",
        ),
        Spacer(1, 0.9 * inch),
        _p(
            s,
            "cover_sub",
            "This specimen is furnished solely for the PartnerLogic retrieval prototype. "
            "It is not a client document and is not legal advice.",
        ),
        PageBreak(),
    ]

    story += [
        _p(s, "h1", "RECITALS"),
        _p(
            s,
            "body",
            "A.&nbsp;&nbsp;The Corporation is a corporation incorporated under <i>The Business Corporations Act, 2021</i> "
            "(Saskatchewan), extra-provincially registered in Alberta and Manitoba, and carrying on the business of "
            "originating, aggregating, and exporting specialty crops from Western Canada (the &quot;Business&quot;).",
        ),
        _p(
            s,
            "body",
            "B.&nbsp;&nbsp;The authorized capital of the Corporation consists of an unlimited number of Class A Common Shares "
            "and an unlimited number of Class B Non-Voting Shares. As of the Effective Date, 10,000,000 Class A Common Shares "
            "are issued and outstanding, and no Class B Non-Voting Shares are issued.",
        ),
        _p(
            s,
            "body",
            "C.&nbsp;&nbsp;The shareholdings as of the Effective Date are: Elkhorn as to 5,500,000 Class A Common Shares (55%); "
            "Northern as to 3,000,000 Class A Common Shares (30%); and the Founder as to 1,500,000 Class A Common Shares (15%).",
        ),
        _p(
            s,
            "body",
            "D.&nbsp;&nbsp;The parties wish to regulate the affairs of the Corporation, the composition of the Board, "
            "the transfer of Shares, and certain exit, information, and restrictive covenant matters, on the terms of this Agreement, "
            "which is intended to be a unanimous shareholder agreement within the meaning of the Act.",
        ),
        _p(
            s,
            "body",
            "NOW THEREFORE in consideration of the mutual covenants herein and other good and valuable consideration, "
            "the receipt and sufficiency of which are acknowledged, the parties agree as follows:",
        ),
        _p(s, "h1", "ARTICLE 1 — INTERPRETATION"),
        _p(s, "h2", "1.1&nbsp;&nbsp;Definitions"),
        _p(s, "body", "In this Agreement, unless the context otherwise requires:"),
        _p(
            s,
            "defn",
            "&quot;<b>Act</b>&quot; means <i>The Business Corporations Act, 2021</i> (Saskatchewan), as amended.",
        ),
        _p(
            s,
            "defn",
            "&quot;<b>Affiliate</b>&quot; has the meaning given in the Act, provided that a portfolio company of a financial "
            "sponsor Shareholder shall not be an Affiliate of that Shareholder solely by reason of common ownership by the sponsor.",
        ),
        _p(
            s,
            "defn",
            "&quot;<b>Board</b>&quot; means the board of directors of the Corporation.",
        ),
        _p(
            s,
            "defn",
            "&quot;<b>Business Day</b>&quot; means a day other than a Saturday, Sunday, or statutory holiday in Saskatchewan.",
        ),
        _p(
            s,
            "defn",
            "&quot;<b>Competitor</b>&quot; means any Person whose principal business is the origination, aggregation, processing, "
            "or export of pulses, oilseeds, or specialty crops in Canada, the United States, or any member state of the European Union.",
        ),
        _p(
            s,
            "defn",
            "&quot;<b>Drag Threshold</b>&quot; means Shareholders holding not less than two-thirds (66.67%) of the outstanding "
            "Class A Common Shares.",
        ),
        _p(
            s,
            "defn",
            "&quot;<b>Fair Market Value</b>&quot; means the cash price at which Shares would change hands between a willing buyer "
            "and a willing seller, neither being under compulsion, determined without minority discount or control premium unless "
            "this Agreement expressly provides otherwise, and expressed in Canadian dollars.",
        ),
        _p(
            s,
            "defn",
            "&quot;<b>Permitted Transferee</b>&quot; means (a) an Affiliate of a Shareholder; (b) a trust, the sole beneficiaries "
            "of which are the Shareholder and members of the Shareholder's Immediate Family; and (c) in the case of the Founder, "
            "a holding company wholly owned by the Founder.",
        ),
        _p(
            s,
            "defn",
            "&quot;<b>Person</b>&quot; includes an individual, corporation, partnership, trust, unincorporated organization, "
            "and any government or agency thereof.",
        ),
        _p(
            s,
            "defn",
            "&quot;<b>Shares</b>&quot; means issued and outstanding shares in the capital of the Corporation, of any class, "
            "and includes any option, warrant, conversion right, or other right to acquire shares.",
        ),
        _p(
            s,
            "defn",
            "&quot;<b>Transfer</b>&quot; includes any sale, assignment, gift, pledge, hypothecation, or other disposition, "
            "whether voluntary, involuntary, or by operation of law, and &quot;Transferred&quot; has a corresponding meaning.",
        ),
        _p(s, "h2", "1.2&nbsp;&nbsp;Interpretation"),
        _p(
            s,
            "body",
            "Headings are for convenience only. The words &quot;including&quot; and &quot;includes&quot; mean including without "
            "limitation. A reference to currency is to lawful money of Canada. If any provision is held invalid, the remaining "
            "provisions continue in full force. This Agreement is drafted in English; the French version, if any, is for convenience only.",
        ),
        _p(s, "h1", "ARTICLE 2 — SHARE CAPITAL AND OWNERSHIP"),
        _p(s, "h2", "2.1&nbsp;&nbsp;Shareholdings"),
        _p(
            s,
            "body",
            "Each Shareholder represents that it is the registered and beneficial owner of the Shares set out opposite its name "
            "in Schedule A, free of Encumbrances other than those arising under this Agreement and the constating documents. "
            "The Corporation shall not issue, and no Shareholder shall Transfer, any Shares except in accordance with this Agreement.",
        ),
        _p(s, "h2", "2.2&nbsp;&nbsp;Legend"),
        _p(
            s,
            "body",
            "Share certificates and the securities register shall bear a legend substantially as follows: "
            "&quot;THE SECURITIES REPRESENTED HEREBY ARE SUBJECT TO A UNANIMOUS SHAREHOLDER AGREEMENT MADE AS OF 1 SEPTEMBER 2024, "
            "A COPY OF WHICH IS ON FILE AT THE REGISTERED OFFICE OF THE CORPORATION. ANY TRANSFER IN VIOLATION OF THAT AGREEMENT "
            "IS VOID.&quot;",
        ),
        _p(s, "h2", "2.3&nbsp;&nbsp;No Public Offering"),
        _p(
            s,
            "body",
            "The parties intend that the Corporation remain a private issuer. No Shareholder shall take any step that would "
            "reasonably be expected to require the Corporation to become a reporting issuer under Saskatchewan, Alberta, or "
            "Manitoba securities laws, without the prior written consent of the Drag Threshold.",
        ),
        _p(s, "h1", "ARTICLE 3 — TRANSFER RESTRICTIONS AND RIGHT OF FIRST REFUSAL"),
        _p(s, "h2", "3.1&nbsp;&nbsp;General prohibition"),
        _p(
            s,
            "body",
            "No Shareholder shall Transfer any Shares except (a) to a Permitted Transferee that first agrees in writing to be "
            "bound by this Agreement; (b) pursuant to the right of first refusal in Section 3.3; (c) pursuant to the tag-along "
            "right in Article 4; (d) pursuant to the drag-along right in Article 5; (e) pursuant to the buy-sell procedure in "
            "Article 6; or (f) with the prior written consent of Shareholders holding at least 90% of the Class A Common Shares, "
            "excluding the Shares proposed to be Transferred.",
        ),
        _p(s, "h2", "3.2&nbsp;&nbsp;Lock-up"),
        _p(
            s,
            "body",
            "Notwithstanding Section 3.1, no Shareholder shall Transfer any Shares to a Person other than a Permitted Transferee "
            "during the period of eighteen (18) months following the Effective Date (the &quot;Lock-up Period&quot;), except "
            "pursuant to a drag-along sale under Article 5 or a buy-sell under Article 6. Transfers to Competitors are prohibited "
            "during the Lock-up Period in all circumstances.",
        ),
        _p(s, "h2", "3.3&nbsp;&nbsp;Right of first refusal"),
        _p(
            s,
            "body",
            "If a Shareholder (the &quot;Offeror&quot;) receives a bona fide written offer from an arm's-length third party "
            "(the &quot;Third-Party Offer&quot;) to purchase Shares, and the Offeror wishes to accept it, the Offeror shall first "
            "deliver a written notice (the &quot;ROFR Notice&quot;) to the Corporation and the other Shareholders. The ROFR Notice "
            "shall attach the Third-Party Offer and state the number of Shares, the cash price in Canadian dollars per Share, "
            "the identity of the proposed transferee, and all other material terms. The price under this Section 3.3 must be "
            "payable 100% in cash at closing; any non-cash consideration is deemed to have a cash value of nil for ROFR purposes "
            "unless the other Shareholders agree otherwise in writing.",
        ),
        _p(
            s,
            "body",
            "The Corporation shall have a first right, exercisable by written notice within ten (10) Business Days after receipt "
            "of the ROFR Notice, to purchase all (but not less than all) of the offered Shares on the terms of the Third-Party Offer. "
            "If the Corporation declines or fails to exercise, the other Shareholders shall have a second right, exercisable within "
            "a further fifteen (15) Business Days, to purchase the offered Shares pro rata to their holdings of Class A Common Shares "
            "(excluding the Offeror), with a right of oversubscription as among exercising Shareholders. The combined exercise period "
            "shall not exceed twenty-five (25) Business Days from delivery of the ROFR Notice.",
        ),
        _p(
            s,
            "body",
            "If the Corporation and the other Shareholders do not collectively elect to purchase all offered Shares, the Offeror "
            "may, during the following forty-five (45) days only, Transfer all (but not less than all) of the offered Shares to the "
            "identified third party at a price not less than, and on terms no more favourable to the transferee than, those in the "
            "ROFR Notice. Any Transfer to a Competitor requires the prior written consent of the Board, which may be withheld in "
            "the Board's sole discretion. A Transfer that is not completed within that forty-five day period again becomes subject "
            "to this Article 3.",
        ),
        _p(s, "h2", "3.4&nbsp;&nbsp;Void transfers"),
        _p(
            s,
            "body",
            "Any purported Transfer in breach of this Article 3 is void, confers no rights on the purported transferee, and "
            "shall not be entered in the securities register. The Corporation is entitled to treat the purported transferor as "
            "the continuing holder for all purposes.",
        ),
        _p(s, "h1", "ARTICLE 4 — TAG-ALONG RIGHTS"),
        _p(s, "h2", "4.1&nbsp;&nbsp;Trigger"),
        _p(
            s,
            "body",
            "If one or more Shareholders propose to Transfer, in a single transaction or a series of related transactions, "
            "Class A Common Shares representing 10% or more of the outstanding Class A Common Shares to a Person other than a "
            "Permitted Transferee (a &quot;Tag Sale&quot;), the selling Shareholder(s) shall give at least twenty (20) Business Days' "
            "prior written notice to the other Shareholders (the &quot;Tag Notice&quot;).",
        ),
        _p(s, "h2", "4.2&nbsp;&nbsp;Participation"),
        _p(
            s,
            "body",
            "Each non-selling Shareholder may elect, by notice within fifteen (15) Business Days after the Tag Notice, to sell "
            "a pro rata portion of its Class A Common Shares on the same price per Share and otherwise on the same terms as the "
            "Tag Sale. &quot;Pro rata&quot; means the proportion that the electing Shareholder's Class A Common Shares bear to "
            "all Class A Common Shares held by Shareholders participating in the Tag Sale, including the original selling Shareholder(s). "
            "The Founder may, in any Tag Sale, elect to include all of the Founder's Shares (and not merely a pro rata portion) "
            "if the Tag Sale would leave the Founder holding less than 5% of the outstanding Class A Common Shares.",
        ),
        _p(s, "h2", "4.3&nbsp;&nbsp;Same terms"),
        _p(
            s,
            "body",
            "Tagging Shareholders shall not be required to provide any representation, warranty, or indemnity other than as to "
            "title to their own Shares, due authorization, and the absence of conflicts, and their liability shall be several "
            "(not joint) and capped at the proceeds actually received by that Shareholder.",
        ),
        _p(s, "h1", "ARTICLE 5 — DRAG-ALONG RIGHTS"),
        _p(s, "h2", "5.1&nbsp;&nbsp;Drag-along sale"),
        _p(
            s,
            "body",
            "If Shareholders constituting the Drag Threshold approve a bona fide arm's-length sale of all, or substantially all, "
            "of the outstanding Shares or of all or substantially all of the assets of the Corporation (a &quot;Drag Sale&quot;), "
            "those Shareholders (the &quot;Dragging Shareholders&quot;) may require all other Shareholders to sell their Shares "
            "on the same price per Share and otherwise on the same terms as the Dragging Shareholders. The Dragging Shareholders "
            "shall deliver a Drag Notice at least twenty-five (25) Business Days before the proposed closing, describing the "
            "purchaser, price, form of consideration, and expected closing date.",
        ),
        _p(s, "h2", "5.2&nbsp;&nbsp;Minority protections"),
        _p(
            s,
            "body",
            "A Drag Sale may not be imposed if: (a) the consideration is other than cash or freely tradeable securities of a "
            "reporting issuer listed on the TSX, TSX Venture, or NYSE, unless each dragged Shareholder may elect cash in lieu "
            "based on Fair Market Value determined by an independent valuator appointed by the Board; (b) the purchaser is an "
            "Affiliate of a Dragging Shareholder, unless the price is not less than Fair Market Value as determined by that valuator; "
            "or (c) the Drag Sale would close during the Lock-up Period, unless the Board (excluding nominees of the Dragging "
            "Shareholders) unanimously consents. Dragged Shareholders' liability shall be several and capped at proceeds received.",
        ),
        _p(s, "h2", "5.3&nbsp;&nbsp;Power of attorney"),
        _p(
            s,
            "body",
            "Each Shareholder hereby irrevocably appoints the Chair of the Board as its attorney to execute transfer forms, "
            "share certificates, and closing deliverables required to complete a Drag Sale conducted in accordance with this Article 5. "
            "The power of attorney is coupled with an interest and survives the Shareholder's insolvency or incapacity.",
        ),
        _p(s, "h1", "ARTICLE 6 — SHOTGUN BUY-SELL"),
        _p(s, "h2", "6.1&nbsp;&nbsp;Offer"),
        _p(
            s,
            "body",
            "At any time after the second anniversary of the Effective Date, any Shareholder holding at least 15% of the "
            "Class A Common Shares (the &quot;Initiating Shareholder&quot;) may deliver a written offer (the &quot;Shotgun Offer&quot;) "
            "to the other Shareholders stating a single all-cash price per Class A Common Share in Canadian dollars (the &quot;Shotgun Price&quot;) "
            "at which the Initiating Shareholder offers either to purchase all Shares held by the recipients or to sell all of the "
            "Initiating Shareholder's Shares. The Shotgun Offer shall be irrevocable for sixty (60) days and shall not include "
            "any earn-out, vendor take-back, or other deferred consideration.",
        ),
        _p(s, "h2", "6.2&nbsp;&nbsp;Election"),
        _p(
            s,
            "body",
            "Within sixty (60) days after receipt of the Shotgun Offer (the &quot;Election Period&quot;), the recipient Shareholders "
            "acting by simple majority of their Class A Common Shares shall elect in writing either to (a) sell all of their Shares "
            "to the Initiating Shareholder at the Shotgun Price, or (b) purchase all of the Initiating Shareholder's Shares at the "
            "Shotgun Price. If the recipients fail to elect within the Election Period, they are conclusively deemed to have elected "
            "to sell. Closing shall occur on the ninetieth (90th) day after expiry of the Election Period, or the next Business Day, "
            "against payment in immediately available funds to an account in Saskatoon or Calgary.",
        ),
        _p(s, "h2", "6.3&nbsp;&nbsp;Default"),
        _p(
            s,
            "body",
            "If a party obliged to purchase fails to close, the non-defaulting party may, as its sole remedy in lieu of specific "
            "performance, elect within ten (10) Business Days to reverse the transaction at 90% of the Shotgun Price, in which case "
            "the defaulting party shall sell, and the non-defaulting party shall purchase, all of the defaulting party's Shares. "
            "Interest at the Royal Bank of Canada prime rate plus 4% per annum shall accrue on overdue amounts.",
        ),
        _p(s, "h1", "ARTICLE 7 — PRE-EMPTIVE RIGHTS"),
        _p(
            s,
            "body",
            "If the Corporation proposes to issue any Shares or securities convertible into Shares for cash (an &quot;Issuance&quot;), "
            "it shall first offer those securities to the Shareholders pro rata to their Class A Common Share holdings, on the same "
            "terms, by written notice specifying price, number, and a subscription period of not less than fifteen (15) Business Days. "
            "Unsubscribed securities may be offered to the other Shareholders for a further five (5) Business Days, and thereafter "
            "to third parties for not more than sixty (60) days at a price not less than, and on terms no more favourable than, "
            "those offered to Shareholders. This Article 7 does not apply to (a) Shares issued under a Board-approved employee "
            "option plan covering in aggregate not more than 5% of the outstanding Class A Common Shares; (b) Shares issued on "
            "conversion of already outstanding convertible securities issued in compliance with this Agreement; or (c) Shares issued "
            "as consideration in an arm's-length acquisition approved as a Reserved Matter.",
        ),
        _p(s, "h1", "ARTICLE 8 — BOARD OF DIRECTORS AND GOVERNANCE"),
        _p(s, "h2", "8.1&nbsp;&nbsp;Size and nominees"),
        _p(
            s,
            "body",
            "The Board shall consist of five (5) directors. For so long as Elkhorn holds at least 40% of the Class A Common Shares, "
            "Elkhorn is entitled to nominate three (3) directors. For so long as Northern holds at least 20%, Northern is entitled "
            "to nominate one (1) director. For so long as the Founder holds at least 10%, the Founder is entitled to nominate one (1) "
            "director, who may be the Founder. If a Shareholder falls below the applicable threshold, its nominee(s) shall resign "
            "promptly on written request of the Board, and the vacant seat(s) shall be filled by nominees of the remaining Shareholders "
            "in proportion to their then holdings, rounded to the nearest whole director, provided the Board remains at five.",
        ),
        _p(s, "h2", "8.2&nbsp;&nbsp;Chair and meetings"),
        _p(
            s,
            "body",
            "The Chair of the Board shall be one of the Elkhorn nominees. The Chair has a second or casting vote only in the event "
            "of an equality of votes on a matter that is not a Reserved Matter. The Board shall meet at least quarterly, in Saskatoon, "
            "Calgary, or by electronic means. Quorum is a majority of directors, including at least one Elkhorn nominee and at least "
            "one nominee of another Shareholder. Notice of meetings shall be given not less than five (5) Business Days in advance, "
            "except in an emergency declared by the Chair acting reasonably.",
        ),
        _p(s, "h2", "8.3&nbsp;&nbsp;Officers"),
        _p(
            s,
            "body",
            "The Founder shall serve as Chief Executive Officer unless removed by the Board for Cause, or by a resolution of the "
            "Board including the affirmative vote of at least one non-Elkhorn director. &quot;Cause&quot; means wilful misconduct, "
            "material breach of this Agreement or of a written employment agreement that remains uncured for fifteen (15) days after "
            "notice, fraud, or conviction of an indictable offence. The Chief Financial Officer shall be appointed by the Board on "
            "the recommendation of Elkhorn.",
        ),
        _p(s, "h1", "ARTICLE 9 — RESERVED MATTERS"),
        _p(
            s,
            "body",
            "Notwithstanding anything to the contrary, the Corporation shall not, and the Board shall not authorize the Corporation to, "
            "take any of the following actions without the prior written approval of Shareholders holding at least 75% of the "
            "Class A Common Shares (each, a &quot;Reserved Matter&quot;):",
        ),
        _p(
            s,
            "defn",
            "(a) issue Shares or other securities, other than under Article 7 or an exempt employee plan described in Article 7;",
        ),
        _p(
            s,
            "defn",
            "(b) incur, assume, or guarantee indebtedness for borrowed money exceeding CAD $500,000 in the aggregate, other than "
            "draws under a Board-approved operating facility with a Canadian chartered bank;",
        ),
        _p(
            s,
            "defn",
            "(c) enter into, amend, or terminate any contract with a Shareholder or an Affiliate of a Shareholder, other than "
            "on arm's-length terms approved by the disinterested directors;",
        ),
        _p(
            s,
            "defn",
            "(d) sell, lease, or otherwise dispose of all or substantially all of the assets of the Corporation, or any assets "
            "having a book or Fair Market Value exceeding CAD $1,000,000 in a twelve-month period;",
        ),
        _p(
            s,
            "defn",
            "(e) amalgamate, merge, continue into another jurisdiction, or commence a voluntary proceeding under the "
            "<i>Bankruptcy and Insolvency Act</i> (Canada) or the <i>Companies' Creditors Arrangement Act</i> (Canada);",
        ),
        _p(
            s,
            "defn",
            "(f) change the size of the Board, amend the articles or by-laws, or alter the rights attaching to any class of Shares;",
        ),
        _p(
            s,
            "defn",
            "(g) declare or pay any dividend or other distribution, other than a distribution required to permit a Shareholder "
            "that is a flow-through entity to meet a demonstrated tax distribution obligation, in an amount certified by the CFO; or",
        ),
        _p(
            s,
            "defn",
            "(h) appoint or remove the auditor, or change the financial year end.",
        ),
        _p(s, "h1", "ARTICLE 10 — INFORMATION RIGHTS"),
        _p(
            s,
            "body",
            "The Corporation shall deliver to each Shareholder: (a) monthly management accounts within twenty (20) days after "
            "month-end; (b) unaudited quarterly financial statements within forty-five (45) days after quarter-end; (c) audited "
            "annual financial statements prepared in accordance with IFRS within one hundred twenty (120) days after year-end; "
            "and (d) an annual budget and operating plan not later than thirty (30) days before the start of each financial year. "
            "Each Shareholder holding at least 10% of the Class A Common Shares may, once per calendar year on ten (10) Business Days' "
            "notice, inspect the books and records of the Corporation during ordinary business hours at the registered office in "
            "Saskatoon, and may cause a single audit or review at that Shareholder's expense, unless the inspection reveals a "
            "material misstatement, in which case the Corporation shall bear the cost. Information received under this Article 10 "
            "is Confidential Information.",
        ),
        _p(s, "h1", "ARTICLE 11 — RESTRICTIVE COVENANTS"),
        _p(s, "h2", "11.1&nbsp;&nbsp;Non-competition"),
        _p(
            s,
            "body",
            "During the period that a Shareholder holds Shares and for twenty-four (24) months after that Shareholder ceases to "
            "hold any Shares (the &quot;Restricted Period&quot;), that Shareholder shall not, anywhere in the Provinces of "
            "British Columbia, Alberta, Saskatchewan, or Manitoba (the &quot;Territory&quot;), directly or indirectly carry on, "
            "be engaged in, or have a financial interest in a Competitor, other than ownership of less than 5% of the listed "
            "securities of a reporting issuer. The Founder additionally agrees that, during her employment and the Restricted Period, "
            "she shall not solicit any person who was a customer, grower, or supplier of the Corporation during the twelve (12) months "
            "preceding the date she ceases to hold Shares, in respect of products competitive with the Business.",
        ),
        _p(s, "h2", "11.2&nbsp;&nbsp;Non-solicitation of personnel"),
        _p(
            s,
            "body",
            "During the Restricted Period, no Shareholder shall solicit or hire any employee of the Corporation earning more than "
            "CAD $80,000 per year, or any officer or director, other than by general advertisement not targeted at Corporation personnel. "
            "The parties acknowledge that these covenants are reasonable given the nature of the Business and the confidential "
            "grower relationships in the Territory, and that the Corporation would not have entered into this Agreement without them. "
            "If a court of competent jurisdiction finds any covenant overbroad, that court is requested to read it down to the "
            "maximum enforceable scope.",
        ),
        _p(s, "h1", "ARTICLE 12 — CONFIDENTIALITY"),
        _p(
            s,
            "body",
            "&quot;Confidential Information&quot; means all non-public information relating to the Corporation, the Business, "
            "grower lists, pricing, this Agreement, and the affairs of any Shareholder learned in connection with this Agreement, "
            "but excludes information that is or becomes public other than by breach, is independently developed without use of "
            "Confidential Information, or is required to be disclosed by law or a stock exchange, provided the disclosing party "
            "gives prompt notice where legally permitted. Each party shall hold Confidential Information in confidence and use it "
            "only to perform this Agreement or to monitor its investment. The obligations in this Article 12 survive for five (5) "
            "years after a party ceases to be a Shareholder, and indefinitely in respect of trade secrets and grower lists.",
        ),
        _p(s, "h1", "ARTICLE 13 — DISPUTE RESOLUTION AND GOVERNING LAW"),
        _p(s, "h2", "13.1&nbsp;&nbsp;Negotiation and mediation"),
        _p(
            s,
            "body",
            "If a dispute arises out of this Agreement, the parties shall first attempt in good faith to resolve it by negotiation "
            "between the Chair and the Founder (or another nominee of Northern if the Founder is a party to the dispute). If the "
            "dispute is not resolved within twenty (20) Business Days, any party may refer it to mediation in Saskatoon under the "
            "National Mediation Rules of the ADR Institute of Canada, Inc. Mediation shall be completed within forty-five (45) days "
            "of the mediator's appointment unless extended by agreement.",
        ),
        _p(s, "h2", "13.2&nbsp;&nbsp;Arbitration"),
        _p(
            s,
            "body",
            "If mediation does not resolve the dispute, it shall be referred to final and binding arbitration in Saskatoon, "
            "Saskatchewan, under <i>The Arbitration Act, 1992</i> (Saskatchewan) and the ADRIC Arbitration Rules. The tribunal "
            "shall consist of a single arbitrator if the amount in dispute is less than CAD $2,000,000, and three arbitrators "
            "otherwise. The language of the arbitration is English. The arbitrator(s) may award costs. Judgment on the award may "
            "be entered in the Court of King's Bench for Saskatchewan, judicial centre of Saskatoon. Notwithstanding the foregoing, "
            "a party may seek interim injunctive relief in that Court to protect Confidential Information or enforce Article 11, "
            "and the parties attorn to the exclusive jurisdiction of that Court for such interim relief.",
        ),
        _p(s, "h2", "13.3&nbsp;&nbsp;Governing law"),
        _p(
            s,
            "body",
            "This Agreement is governed by the laws of the Province of Saskatchewan and the federal laws of Canada applicable therein, "
            "without regard to conflict of laws principles that would refer to the laws of another jurisdiction. The United Nations "
            "Convention on Contracts for the International Sale of Goods does not apply.",
        ),
        _p(s, "h1", "ARTICLE 14 — GENERAL"),
        _p(s, "h2", "14.1&nbsp;&nbsp;Entire agreement"),
        _p(
            s,
            "body",
            "This Agreement, including the Schedules, constitutes the entire agreement among the parties concerning its subject matter "
            "and supersedes all prior agreements, including the term sheet dated 12 June 2024 among Elkhorn, Northern, and the Founder. "
            "No amendment is effective unless in writing and signed by Shareholders holding at least 75% of the Class A Common Shares "
            "and, if the amendment adversely affects the Founder in a manner different from other Shareholders, by the Founder.",
        ),
        _p(s, "h2", "14.2&nbsp;&nbsp;Notices"),
        _p(
            s,
            "body",
            "Notices shall be in writing and delivered by hand, courier, or email (with read receipt) to the addresses in Schedule A, "
            "and are deemed received on the date of delivery if delivered on a Business Day before 5:00 p.m. Saskatoon time, and on "
            "the next Business Day otherwise. The Corporation's address for notice is 1500 – 410 22nd Street East, Saskatoon, SK S7K 5T6.",
        ),
        _p(s, "h2", "14.3&nbsp;&nbsp;Assignment and enurement"),
        _p(
            s,
            "body",
            "No party may assign this Agreement except in connection with a Transfer permitted under Article 3. This Agreement "
            "enures to the benefit of and binds the parties and their permitted successors and assigns. Time is of the essence. "
            "This Agreement may be executed in counterparts, including by electronic signature, each of which is deemed an original.",
        ),
        _p(s, "h2", "14.4&nbsp;&nbsp;Independent legal advice"),
        _p(
            s,
            "body",
            "Each party acknowledges that it has been advised to obtain independent legal advice, has had the opportunity to do so, "
            "and enters into this Agreement voluntarily. Nothing in this specimen constitutes legal advice by MLT Aikins LLP or "
            "by PartnerLogic.",
        ),
        PageBreak(),
        _p(s, "h1", "SCHEDULE A — SHAREHOLDERS AND NOTICE PARTICULARS"),
        _p(
            s,
            "body",
            "<b>Elkhorn Capital Partners Ltd.</b> — 5,500,000 Class A Common Shares (55%). Registered office: 3200, 421 7th Avenue SW, "
            "Calgary, Alberta T2P 4K9. Email: notices@elkhorn.example. Nominee directors (initial): Jordan Hale, Priya Nair, "
            "and Samuel Okonkwo. Elkhorn is an Alberta corporation controlled by Elkhorn Fund IV, L.P.",
        ),
        _p(
            s,
            "body",
            "<b>Northern Grain Ventures Inc.</b> — 3,000,000 Class A Common Shares (30%). Registered office: 201 Portage Avenue, "
            "Suite 1800, Winnipeg, Manitoba R3B 3K6. Email: legal@northerngrain.example. Nominee director (initial): Elise Beauregard. "
            "Northern is a Manitoba corporation.",
        ),
        _p(
            s,
            "body",
            "<b>Mara Chen</b> — 1,500,000 Class A Common Shares (15%). Address for notice: 612 Spadina Crescent East, Saskatoon, "
            "Saskatchewan S7K 3G9. Email: mara.chen@prairieharvest.example. The Founder is the initial Chief Executive Officer "
            "and the Founder's nominee director.",
        ),
        _p(s, "h1", "SCHEDULE B — INITIAL BOARD AND OFFICERS"),
        _p(
            s,
            "body",
            "Directors as of the Effective Date: Jordan Hale (Chair), Priya Nair, Samuel Okonkwo, Elise Beauregard, and Mara Chen. "
            "Officers as of the Effective Date: Mara Chen, Chief Executive Officer; Christopher Dahl, Chief Financial Officer "
            "(Elkhorn recommendation); and Anika Singh, Corporate Secretary. The registered office is in Saskatoon, Saskatchewan. "
            "The financial year end is 31 December.",
        ),
        _p(s, "h1", "SCHEDULE C — KEY COMMERCIAL PARAMETERS (FOR EASE OF REFERENCE)"),
        _p(
            s,
            "body",
            "The following summary is for convenience only. If this Schedule C conflicts with the body of the Agreement, "
            "the body prevails. Lock-up Period: 18 months from 1 September 2024. ROFR: Corporation has 10 Business Days, then "
            "other Shareholders have 15 Business Days; residual third-party sale window 45 days; cash only; Board consent required "
            "for any Transfer to a Competitor. Tag-along: triggered at 10% of Class A Common Shares; 15 Business Days to elect; "
            "Founder full-exit overlay if left below 5%. Drag-along: 66.67% threshold; 25 Business Days' notice; cash or listed "
            "paper unless cash election; no Affiliate purchaser below Fair Market Value. Shotgun: available after 2 years; 15% "
            "minimum holder; 60-day election; 90-day close; all cash CAD; default reverse at 90% of price. Pre-emptive: 15 Business "
            "Days plus 5-day oversubscription. Board: five seats (3 Elkhorn / 1 Northern / 1 Founder). Reserved Matters: 75% "
            "Shareholder approval, including debt above CAD $500,000 and asset sales above CAD $1,000,000 in a year. Information: "
            "monthly in 20 days, quarterly in 45, audited annual in 120. Non-compete: 24 months in BC, AB, SK, and MB. "
            "Confidentiality: 5 years (indefinite for trade secrets and grower lists). Governing law: Saskatchewan. "
            "Arbitration: Saskatoon under The Arbitration Act, 1992 (Saskatchewan); interim relief in the Court of King's Bench "
            "for Saskatchewan, judicial centre of Saskatoon.",
        ),
        Spacer(1, 0.4 * inch),
        _p(
            s,
            "center",
            "<i>IN WITNESS WHEREOF the parties have executed this Unanimous Shareholder Agreement as of the Effective Date.</i>",
        ),
        Spacer(1, 0.25 * inch),
        _p(s, "body", "PRAIRIE HARVEST HOLDINGS INC."),
        _p(s, "body", "Per: ___________________________&nbsp;&nbsp;Name: Mara Chen&nbsp;&nbsp;Title: Chief Executive Officer"),
        _p(s, "body", "ELKHORN CAPITAL PARTNERS LTD."),
        _p(s, "body", "Per: ___________________________&nbsp;&nbsp;Name: Jordan Hale&nbsp;&nbsp;Title: Managing Partner"),
        _p(s, "body", "NORTHERN GRAIN VENTURES INC."),
        _p(s, "body", "Per: ___________________________&nbsp;&nbsp;Name: Elise Beauregard&nbsp;&nbsp;Title: Director"),
        _p(s, "body", "MARA CHEN"),
        _p(s, "body", "________________________________&nbsp;&nbsp;Witness: ___________________________"),
    ]
    return story


def main() -> None:
    OUTPUT.parent.mkdir(parents=True, exist_ok=True)
    styles = _styles()
    doc = SimpleDocTemplate(
        str(OUTPUT),
        pagesize=letter,
        leftMargin=0.9 * inch,
        rightMargin=0.9 * inch,
        topMargin=0.85 * inch,
        bottomMargin=0.75 * inch,
        title="Unanimous Shareholder Agreement — Prairie Harvest Holdings Inc.",
        author="PartnerLogic specimen (not a client document)",
    )
    doc.build(build_story(styles), onFirstPage=_header_footer, onLaterPages=_header_footer)
    print(f"Wrote {OUTPUT}")


if __name__ == "__main__":
    main()
