name: Python Bot CI

on:
  push:
    branches: [ main, develop ]
  pull_request:
    branches: [ main ]

permissions:
  contents: read

jobs:
  test:
    runs-on: ubuntu-latest
    
    permissions:
      contents: read
    
    strategy:
      matrix:
        python-version: ['3.11', '3.12']
    
    steps:
    - uses: actions/checkout@v3
    
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v4
      with:
        python-version: ${{ matrix.python-version }}
    
    - name: Install FFmpeg
      run: |
        sudo apt-get update
        sudo apt-get install -y ffmpeg
    
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -r requirements.txt
    
    - name: Verify FFmpeg installation
      run: ffmpeg -version
    
    - name: Check Python syntax
      run: |
        python -m py_compile bot.py
        python -m py_compile config.py
        python -m py_compile database.py
    
    - name: Run setup verification (skip config check)
      run: |
        # Create dummy .env for testing
        cp .env.example .env
        echo "BOT_TOKEN=test_token" >> .env
        echo "API_ID=12345" >> .env
        echo "API_HASH=test_hash" >> .env
    
  lint:
    runs-on: ubuntu-latest
    
    permissions:
      contents: read
    
    steps:
    - uses: actions/checkout@v3
    
    - name: Set up Python
      uses: actions/setup-python@v4
      with:
        python-version: '3.11'
    
    - name: Install linting tools
      run: |
        python -m pip install --upgrade pip
        pip install flake8
    
    - name: Lint with flake8
      run: |
        # Stop the build if there are Python syntax errors or undefined names
        flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
        # Exit-zero treats all errors as warnings
        flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
      continue-on-error: true

  docker:
    runs-on: ubuntu-latest
    
    permissions:
      contents: read
    
    steps:
    - uses: actions/checkout@v3
    
    - name: Build Docker image
      run: docker build -t video-editor-bot:test .
    
    - name: Verify Docker image
      run: docker images | grep video-editor-bot
