import{a as e,i as t,o as n,t as r}from"../secret-file-Cn-n4lbI.js";import{t as i}from"../account-lookup-CW-_CL7y.js";import"../utils-kOqzSjf6.js";function a(e){return r(e,`LINE credential file`,{rejectSymlink:!0})}function o(e){let{accountId:t,baseConfig:n,accountConfig:r}=e;if(r?.channelAccessToken?.trim())return{token:r.channelAccessToken.trim(),tokenSource:`config`};let i=a(r?.tokenFile);if(i)return{token:i,tokenSource:`file`};if(t===`default`){if(n?.channelAccessToken?.trim())return{token:n.channelAccessToken.trim(),tokenSource:`config`};let e=a(n?.tokenFile);if(e)return{token:e,tokenSource:`file`};let t=process.env.LINE_CHANNEL_ACCESS_TOKEN?.trim();if(t)return{token:t,tokenSource:`env`}}return{token:``,tokenSource:`none`}}function s(e){let{accountId:t,baseConfig:n,accountConfig:r}=e;if(r?.channelSecret?.trim())return r.channelSecret.trim();let i=a(r?.secretFile);if(i)return i;if(t===`default`){if(n?.channelSecret?.trim())return n.channelSecret.trim();let e=a(n?.secretFile);if(e)return e;let t=process.env.LINE_CHANNEL_SECRET?.trim();if(t)return t}return``}function c(t){let n=t.cfg,r=e(t.accountId),a=n.channels?.line,c=a?.accounts,l=r===`default`?void 0:i(c,r),{token:u,tokenSource:d}=o({accountId:r,baseConfig:a,accountConfig:l}),f=s({accountId:r,baseConfig:a,accountConfig:l}),{accounts:p,defaultAccount:m,...h}=a??{},g={...h,...l},_=l?.enabled??(r===`default`?a?.enabled??!0:!1);return{accountId:r,name:l?.name??(r===`default`?a?.name:void 0),enabled:_,channelAccessToken:u,channelSecret:f,tokenSource:d,config:g}}function l(e){let n=e.channels?.line,r=n?.accounts,i=new Set;if((n?.channelAccessToken?.trim()||n?.tokenFile||process.env.LINE_CHANNEL_ACCESS_TOKEN?.trim())&&i.add(t),r)for(let e of Object.keys(r))i.add(e);return Array.from(i)}function u(r){let i=n(r.channels?.line?.defaultAccount);if(i&&l(r).some(t=>e(t)===i))return i;let a=l(r);return a.includes(`default`)?t:a[0]??`default`}function d(t){return e(t)}export{t as DEFAULT_ACCOUNT_ID,l as listLineAccountIds,d as normalizeAccountId,u as resolveDefaultLineAccountId,c as resolveLineAccount};
