# Google Drive Integration Guide (Paid Account)

මෙම Polymer පද්ධතිය තුළ Artwork ගොනු (Files) upload කිරීමේදී:
- **&le; 100 KB (100,000 bytes):** Local Private Storage එකෙහි සුරැකේ.
- **&gt; 100 KB:** ඔබගේ Google Drive ගිණුමට ස්වයංක්‍රීයව upload වී, Shareable Preview / Download Link එකක් සාදයි. (Vendor ලාට සහ Internal Staff එකට link එක හරහා බැලිය හැක).
- **Google Drive credentials තවම දමා නැතිනම්:** Request එක හෝ Upload එක fail නොවී, Local Storage එකට Save වේ (Fallback).

---

## ක්‍රමය 1: Service Account මඟින් සම්බන්ධ කිරීම (වඩාත් පහසු සහ නිර්දේශිත ක්‍රමය)

1. [Google Cloud Console](https://console.cloud.google.com/) වෙත යන්න.
2. අලුත් Project එකක් සාදන්න (හෝ පවතින Project එකක් තෝරන්න).
3. **APIs & Services &rarr; Enable APIs and Services** වෙත ගොස් **Google Drive API** search කර **Enable** කරන්න.
4. **IAM & Admin &rarr; Service Accounts** වෙත ගොස්:
   - **Create Service Account** ක්ලික් කර නමක් දෙන්න (උදා: `polymer-drive-uploader`).
   - Service account එක සාදා අවසන් වූ පසු, ඒ මත click කර **Keys** tab එකට යන්න.
   - **Add Key &rarr; Create new key &rarr; JSON** තෝරන්න.
   - Download වන JSON file එක rename කර `google-drive-credentials.json` නමින් පහත path එකට දමන්න:
     ```
     c:\xampp\htdocs\polymer\storage\app\google-drive-credentials.json
     ```
5. **Google Drive Folder එක Share කිරීම:**
   - ඔබගේ Paid Google Drive ගිණුමට ගොස් Artwork සඳහා Folder එකක් සාදන්න (උදා: `Polymer_Artworks`).
   - Folder එක මත Right-click කර **Share** ක්ලික් කරන්න.
   - ඉහත සාදාගත් Service Account Email එක (උදා: `polymer-drive-uploader@project-id.iam.gserviceaccount.com`) **Editor** ලෙස add කර Share කරන්න.
   - Folder URL එකෙන් Folder ID එක ලබාගෙන `.env` හි `GOOGLE_DRIVE_FOLDER_ID` වෙත දමන්න:
     ```env
     GOOGLE_DRIVE_ENABLED=true
     GOOGLE_DRIVE_FOLDER_ID=1a2B3c4D5e6F7g8H9i0JkLmNoPqRsTuVw
     ```

---

## ක්‍රමය 2: OAuth 2.0 Web Client & Refresh Token

ඔබගේ Personal/Company Google Workspace ගිණුමේ OAuth client එකක් භාවිතා කිරීමට අවශ්‍ය නම්:
1. Google Cloud Console හි **APIs & Services &rarr; Credentials** වෙත යන්න.
2. **Create Credentials &rarr; OAuth client ID** (Application type: Web application) තෝරන්න.
3. Redirect URI ලෙස `https://developers.google.com/oauthplayground` එකතු කරන්න.
4. Client ID සහ Client Secret ලබාගෙන `.env` එකට දමන්න:
   ```env
   GOOGLE_DRIVE_ENABLED=true
   GOOGLE_DRIVE_CLIENT_ID=your-client-id.apps.googleusercontent.com
   GOOGLE_DRIVE_CLIENT_SECRET=your-client-secret
   GOOGLE_DRIVE_REFRESH_TOKEN=your-refresh-token
   GOOGLE_DRIVE_FOLDER_ID=your-target-folder-id
   ```

---

## Settings Verification

PHP config cache clear කිරීමට පහත command එක run කරන්න:
```bash
php artisan optimize:clear
```
Google Drive credentials configure කළ පසු, 100 KB වලට වැඩි ඕනෑම Artwork එකක් upload කළ සැනින් Google Drive වෙත upload වී link එක සකස් වේ!
