name: Test
on: [push, pull_request]

jobs:
  # Job 1: Check Solidity Compilation and Solhint
  solidity:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repo
        uses: actions/checkout@v4
      
      - name: Cache NPM dependencies
        uses: actions/cache@v3
        with:
          path: ~/.npm
          key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-node-
      
      - name: Install Dependencies
        run: npm ci
      
      - name: Check Solidity Compilation
        run: npm run sol:compile
      
      - name: Check Solidity Solhint
        run: npm run lint-solc

  # Job 2: Check ESLint
  eslint:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repo
        uses: actions/checkout@v4
      
      - name: Cache NPM dependencies
        uses: actions/cache@v3
        with:
          path: ~/.npm
          key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-node-
      
      - name: Install Dependencies
        run: npm ci
      
      - name: Check ESLint
        run: npm run lint

  # Job 3: Check Internal Links
  linkcheck-internal:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repo
        uses: actions/checkout@v4
      
      - name: Cache NPM dependencies
        uses: actions/cache@v3
        with:
          path: ~/.npm
          key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-node-
      
      - name: Install Dependencies
        run: npm ci
      
      - name: Check Internal Links
        run: npm run linkcheck-internal

  # Job 4: Check Types
  typecheck:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repo
        uses: actions/checkout@v4
      
      - name: Cache NPM dependencies
        uses: actions/cache@v3
        with:
          path: ~/.npm
          key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-node-
      
      - name: Install Dependencies
        run: npm ci
      
      - name: Check Types
        run: npm run typecheck